Skip to content

Commit b0733e0

Browse files
Fix rush changelog; update changefile detection regex and add unit tests (#5315)
1 parent 0aeeb44 commit b0733e0

File tree

8 files changed

+96
-9
lines changed

8 files changed

+96
-9
lines changed

.github/workflows/ci.yml

+3
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,9 @@ jobs:
106106
# Typescript version check
107107
- name: Typescript version compatibility check
108108
run: rush build --only @internal/check-typescript-regression
109+
# Scripts tests
110+
- name: Test scripts/ folder
111+
run: rush test --only @internal/scripts
109112
# Ensure all downstream packlet versions are consitent with the base packlet version
110113
- name: Ensure all package versions are consistent
111114
run: rush ensure-consistent-versions

common/config/rush/pnpm-lock.yaml

+12-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

common/config/rush/variants/stable/pnpm-lock.yaml

+12-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

common/scripts/changelog/utils.mjs

+14-6
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,19 @@
11
// Copyright (c) Microsoft Corporation.
22
// Licensed under the MIT License.
33

4+
// Returns the filename in group1 of the regex match
5+
const CHANGE_FILE_REGEX = /(?:change|change-beta)\/(@azure-communication-react[^\/]*\.json)(?:.*)?$/;
6+
47
export function parseNewChangeFiles(stdout) {
5-
// Split the output into lines
6-
const lines = stdout.split('\n');
7-
// Filter out the empty lines (`lines` list might have empty lines as part of the output)
8-
const matches = lines.filter(line => line && line.toString().trim().length > 0);
8+
// Split the output into lines and filter out the empty lines
9+
const stdoutLines = stdout.split('\n').filter(line => line && line.toString().trim().length > 0);
10+
911
// Parse the change file name from the output (remove the status and return only file information)
10-
return matches.map(line => line.split('\t')[1]);
11-
}
12+
const matches = stdoutLines.map(line => {
13+
const match = line.match(CHANGE_FILE_REGEX);
14+
return match ? match[1] : undefined // Access group 1 (the filename);
15+
}
16+
).filter(Boolean); // Filter out nulls
17+
18+
return matches;
19+
}
+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Copyright (c) Microsoft Corporation.
2+
// Licensed under the MIT License.
3+
4+
import { parseNewChangeFiles } from './utils';
5+
6+
describe('parseNewChangeFiles', () => {
7+
const testFilename = '@azure-communication-react-3ba4c269-8d22-48da-b905-091fdbaf2f98.json';
8+
const testStrings = [
9+
`A change-beta/${testFilename}`,
10+
`A change/${testFilename}`,
11+
`randomfolder/change-beta/${testFilename}random text that should be ignored`,
12+
`\n\nchange/${testFilename}\s \n \t`
13+
];
14+
15+
test('parseNewChangeFiles should return the filenames without folder prefixes or other space characters', () => {
16+
for (const testString of testStrings) {
17+
expect(parseNewChangeFiles(testString)).toStrictEqual([testFilename]);
18+
}
19+
});
20+
21+
test('parseNewChangeFiles should return the filenames when multiple files are seperated by newline characters', () => {
22+
const test = testStrings.join('\n');
23+
const expectedMatch = new Array(testStrings.length).fill(testFilename);
24+
25+
expect(parseNewChangeFiles(test)).toStrictEqual(expectedMatch);
26+
});
27+
28+
test('parseNewChangeFiles should not return unrecognized lines in amonst legitmate changefiles', () => {
29+
const testShouldnotMatch = 'change/randomfile.json';
30+
const tests = [
31+
testStrings[0],
32+
testShouldnotMatch,
33+
testStrings[1]
34+
].join('\n');
35+
36+
expect(parseNewChangeFiles(tests)).toStrictEqual([testFilename, testFilename]);
37+
});
38+
});

common/scripts/jest.config.js

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
2+
module.exports = {
3+
transform: {
4+
'^.+\\.jsx?$': ['babel-jest', { configFile: './scripts-tests-setup/babel-config-jest.js' }],
5+
'^.+\\.mjs$': ['babel-jest', { configFile: './scripts-tests-setup/babel-config-jest.js' }],
6+
},
7+
};

common/scripts/package.json

+5-1
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,18 @@
99
"build": "",
1010
"build:stable": "",
1111
"clean": "",
12-
"test": "",
12+
"test": "jest",
1313
"test:ci-coverage": "",
1414
"test:stable": "",
1515
"prettier": "",
1616
"prettier:check": ""
1717
},
1818
"devDependencies": {
19+
"@babel/preset-env": "7.23.9",
20+
"@jest/transform": "29.7.0",
1921
"@types/yargs": "^17.0.29",
22+
"babel-jest": "^29.5.0",
23+
"jest": "29.7.0",
2024
"yargs": "^17.7.2"
2125
}
2226
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module.exports = {
2+
presets: [
3+
'@babel/preset-env' // to support `import` syntax in test files
4+
]
5+
};

0 commit comments

Comments
 (0)