Skip to content

Commit fdf75e9

Browse files
committed
feat(scripts): sort subscripts of the test suites
1 parent f649aad commit fdf75e9

File tree

3 files changed

+47
-2
lines changed

3 files changed

+47
-2
lines changed

src/package/scripts/script-comparator.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ function getBaseScriptOf(script) {
1717
function getCategoryOrder(base) {
1818
if ('test' === base) return 0;
1919
if (base.startsWith('lint:')) return 1;
20-
if ('test:unit' === base) return 2;
21-
if ('test:integration' === base) return 3;
20+
if (base.startsWith('test:unit')) return 2;
21+
if (base.startsWith('test:integration')) return 3;
2222
if (base.startsWith('test:')) return 2;
2323

2424
return 4;
@@ -36,5 +36,8 @@ export default function compareScriptNames(a, b) {
3636
const categoryDiff = getCategoryOrder(aBase) - getCategoryOrder(bBase);
3737
if (0 !== categoryDiff) return 0 > categoryDiff ? -1 : 1;
3838

39+
const baseCompare = aBase.localeCompare(bBase);
40+
if (0 !== baseCompare) return 0 > baseCompare ? -1 : 1;
41+
3942
return a.localeCompare(b);
4043
}

src/package/scripts/script-comparator.test.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,24 @@ describe('script name comparator', () => {
8080
expect(compareScriptNames('test:integration', 'test:unit')).toEqual(A_AFTER_B);
8181
});
8282

83+
it('should sort `test:unit` sub-scripts after `test:unit`', async () => {
84+
expect(compareScriptNames('test:unit', 'test:unit:base')).toEqual(A_BEFORE_B);
85+
expect(compareScriptNames('test:unit:base', 'test:unit')).toEqual(A_AFTER_B);
86+
});
87+
88+
it('should sort `test:integration` sub-scripts after `test:integration`', async () => {
89+
expect(compareScriptNames('test:integration', 'test:integration:base')).toEqual(A_BEFORE_B);
90+
expect(compareScriptNames('test:integration:base', 'test:integration')).toEqual(A_AFTER_B);
91+
92+
expect(compareScriptNames('test:integration', 'pretest:integration:base')).toEqual(A_BEFORE_B);
93+
expect(compareScriptNames('pretest:integration:base', 'test:integration')).toEqual(A_AFTER_B);
94+
});
95+
96+
it('should sort `test:unit` sub-scripts ahead of `test:integration`', async () => {
97+
expect(compareScriptNames('test:unit:base', 'test:integration')).toEqual(A_BEFORE_B);
98+
expect(compareScriptNames('test:integration', 'test:unit:base')).toEqual(A_AFTER_B);
99+
});
100+
83101
it('should sort uncategorized scripts below `test:` scripts', async () => {
84102
expect(compareScriptNames(any.word(), `test:${any.word()}`)).toEqual(A_AFTER_B);
85103
expect(compareScriptNames(`test:${any.word()}`, any.word())).toEqual(A_BEFORE_B);

test/integration/features/step_definitions/scripts-steps.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,14 @@ Before(function () {
99
test: any.string(),
1010
'lint:md': any.string(),
1111
prepare: any.string(),
12+
'pretest:integration:base': any.string(),
13+
'test:unit:base': any.string(),
14+
'test:integration:base': any.string(),
15+
'test:integration:debug': any.string(),
16+
'test:integration:focus': any.string(),
17+
'test:integration:focus:debug': any.string(),
18+
'test:integration:wip': any.string(),
19+
'test:integration:wip:debug': any.string(),
1220
'test:unit': any.string(),
1321
pretest: any.string(),
1422
'prelint:publish': 'run-s build',
@@ -80,6 +88,14 @@ Then('the scripts are ordered correctly', async function () {
8088
test,
8189
'test:unit': testUnit,
8290
'test:integration': testIntegration,
91+
'pretest:integration:base': pretestIntegrationBase,
92+
'test:integration:base': testIntegrationBase,
93+
'test:integration:debug': testIntegrationDebug,
94+
'test:integration:focus': testIntegrationFocus,
95+
'test:unit:base': testUnitBase,
96+
'test:integration:focus:debug': testIntegrationFocusDebug,
97+
'test:integration:wip': testIntegrationWip,
98+
'test:integration:wip:debug': testIntegrationWipDebug,
8399
'prelint:publish': prelintPublish,
84100
'lint:md': lintMd,
85101
...otherExistingScripts
@@ -95,7 +111,15 @@ Then('the scripts are ordered correctly', async function () {
95111
'prelint:publish',
96112
'lint:publish',
97113
'test:unit',
114+
'test:unit:base',
98115
'test:integration',
116+
'pretest:integration:base',
117+
'test:integration:base',
118+
'test:integration:debug',
119+
'test:integration:focus',
120+
'test:integration:focus:debug',
121+
'test:integration:wip',
122+
'test:integration:wip:debug',
99123
...Object.keys(otherExistingScripts).sort((a, b) => a.localeCompare(b))
100124
]
101125
);

0 commit comments

Comments
 (0)