Skip to content

Commit f9eca9d

Browse files
committed
fix: handle non-deterministic async order and revert unnecessary changes
1 parent 7924e45 commit f9eca9d

File tree

2 files changed

+24
-8
lines changed

2 files changed

+24
-8
lines changed

src/actions/runNpmScript.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ import { runAll } from '../helpers/runAll'
33
export function runNpmScript(scriptNameTag, args = [], providedPackageNames) {
44
return function runNpmScript({ config, npm, resolve }) {
55
const scriptName = resolve.value(scriptNameTag)
6-
const packages =
7-
providedPackageNames || Object.keys(config.packagesPaths).sort()
6+
const packages = providedPackageNames || Object.keys(config.packagesPaths)
87

98
return runAll(
109
packages.map((name) => npm.runScript(name, scriptName, args))

test/utils/testAction.js

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,21 @@ import { options, runCommandMock } from 'test-utils'
33
import { Cooker } from 'repo-cooker'
44
import assert from 'test-utils/assert'
55

6+
function normalizeOutput(output) {
7+
return Object.keys(output).reduce((acc, key) => {
8+
const value = output[key]
9+
// Sort commands array to handle non-deterministic async order
10+
if (key === 'commands' && Array.isArray(value)) {
11+
acc[key] = [...value].sort((a, b) =>
12+
(a.options?.cwd || '').localeCompare(b.options?.cwd || '')
13+
)
14+
} else {
15+
acc[key] = value
16+
}
17+
return acc
18+
}, {})
19+
}
20+
621
export function testAction(
722
action,
823
input,
@@ -13,7 +28,7 @@ export function testAction(
1328
) {
1429
const dryRun = runCommandMock()
1530
const fullOptions = Object.assign({}, options, { dryRun }, extraOptions)
16-
const cooker = Cooker(['--no-parallel'], fullOptions)
31+
const cooker = Cooker(fullOptions)
1732

1833
cooker
1934
.run([
@@ -26,11 +41,13 @@ export function testAction(
2641
action,
2742
({ props }) => {
2843
assert.deepEqual(
29-
Object.keys(output).reduce((acc, key) => {
30-
acc[key] = props[key]
31-
return acc
32-
}, {}),
33-
output,
44+
normalizeOutput(
45+
Object.keys(output).reduce((acc, key) => {
46+
acc[key] = props[key]
47+
return acc
48+
}, {})
49+
),
50+
normalizeOutput(output),
3451
done
3552
)
3653
},

0 commit comments

Comments
 (0)