Skip to content

Commit ddd53f9

Browse files
committed
fix test flake with non-deterministic build
1 parent efbf69c commit ddd53f9

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

scripts/plugin-tests.js

+11-4
Original file line numberDiff line numberDiff line change
@@ -2887,17 +2887,24 @@ let syncTests = {
28872887
assert.strictEqual(e.message.split('\n')[0], 'Build failed with 1 error:')
28882888
assert.strictEqual(e.errors[0].text,
28892889
'Detected inconsistent metadata for the path "scripts/.plugin-tests/testNonDeterministicBuild/src/c.js" when it was imported here:')
2890-
assert.strictEqual(e.errors[0].notes.map(x => x.text).join('\n'), `The original metadata for that path comes from when it was imported here:
2890+
2891+
const expectedError = sideEffects => `The original metadata for that path comes from when it was imported here:
28912892
The difference in metadata is displayed below:
28922893
28932894
{
2894-
- "sideEffects": true,
2895-
+ "sideEffects": false,
2895+
- "sideEffects": ${!sideEffects},
2896+
+ "sideEffects": ${sideEffects},
28962897
}
28972898
28982899
This is a bug in the "some-plugin" plugin. Plugins provide metadata for a given path in an "onResolve" callback. \
28992900
All metadata provided for the same path must be consistent to ensure deterministic builds. Due to parallelism, \
2900-
one set of provided metadata will be randomly chosen for a given path, so providing inconsistent metadata for the same path can cause non-determinism.`)
2901+
one set of provided metadata will be randomly chosen for a given path, so providing inconsistent metadata for the same path can cause non-determinism.`
2902+
2903+
// Try both orders to avoid flakes (since this test is deliberately non-deterministic)
2904+
const observedError = e.errors[0].notes.map(x => x.text).join('\n')
2905+
if (observedError !== expectedError(false) && observedError !== expectedError(true)) {
2906+
assert.strictEqual(observedError, expectedError(true))
2907+
}
29012908
}
29022909
},
29032910
}

0 commit comments

Comments
 (0)