Skip to content

Commit

Permalink
build: fix issues on win32
Browse files Browse the repository at this point in the history
  • Loading branch information
noomorph committed Oct 10, 2023
1 parent 2c29a9c commit 70904fe
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 27 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ jobs:
matrix:
os:
- ubuntu-latest
- windows-latest
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
Expand Down
2 changes: 1 addition & 1 deletion e2e/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const fixturesDir = path.join(__dirname, '__fixtures__');
const getEvents = (glob, filterFn) => {
return globby.sync(`*.x.x/${glob}/*.json`, { cwd: fixturesDir })
.map(f => [
path.join(path.dirname(f), path.basename(f, '.json')),
path.join(path.dirname(f), path.basename(f, '.json')).replaceAll(path.win32.sep, path.posix.sep),
require('./__fixtures__/' + f).filter(filterFn),
]);
};
Expand Down
1 change: 1 addition & 0 deletions e2e/jest-benchmark.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const mixins = {
}),
reporter: (enable) => ({
reporters: [
'summary',
...(enable ? ['jest-metadata/reporter'] : []),
'./reporters/benchmark',
],
Expand Down
26 changes: 2 additions & 24 deletions e2e/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,31 +12,9 @@
"semver": "^7.5.4"
},
"scripts": {
"build": "npm run build:default && npm run build:bail",
"build:jsdom": "cross-env JEST_ENVIRONMENT=jsdom npm run build",
"build:node": "cross-env JEST_ENVIRONMENT=node npm run build",
"build:default": "npm run build:env-1 ; npm run build:env-N ; npm run build:no-env-1 ; npm run build:no-env-N ; true",
"build:bail": "npm run build:bail-env-1 ; npm run build:bail-env-N ; npm run build:bail-no-env-1 ; npm run build:bail-no-env-N ; true",
"build:env-1": "cross-env PRESET=env-1 MODE=recorder jest",
"build:env-N": "cross-env PRESET=env-N MODE=recorder jest",
"build:no-env-1": "cross-env PRESET=no-env-1 MODE=recorder jest",
"build:no-env-N": "cross-env PRESET=no-env-N MODE=recorder jest",
"build:bail-env-1": "cross-env PRESET=bail-env-1 MODE=recorder jest",
"build:bail-env-N": "cross-env PRESET=bail-env-N MODE=recorder jest",
"build:bail-no-env-1": "cross-env PRESET=bail-no-env-1 MODE=recorder jest",
"build:bail-no-env-N": "cross-env PRESET=bail-no-env-N MODE=recorder jest",
"bench": "npm run bench:1 && npm run bench:10 && npm run bench:100 && npm run bench:1000 && npm run bench:10000",
"bench:1": "cross-env NUM_TESTS=1 npm run bench:every",
"bench:10": "cross-env NUM_TESTS=10 npm run bench:every",
"bench:100": "cross-env NUM_TESTS=100 npm run bench:every",
"bench:1000": "cross-env NUM_TESTS=1000 npm run bench:every",
"bench:10000": "cross-env NUM_TESTS=10000 npm run bench:every",
"bench:every": "npm run bench:baseline-1 ; npm run bench:baseline-N ; npm run bench:fallback-1 ; npm run bench:fallback-N ; npm run bench:metadata-1 ; npm run bench:metadata-N ; true",
"bench:metadata-1": "cross-env PRESET=metadata-1 MODE=benchmark jest",
"bench:metadata-N": "cross-env PRESET=metadata-N MODE=benchmark jest",
"bench:fallback-1": "cross-env PRESET=fallback-1 MODE=benchmark jest",
"bench:fallback-N": "cross-env PRESET=fallback-N MODE=benchmark jest",
"bench:baseline-1": "cross-env PRESET=baseline-1 MODE=benchmark jest",
"bench:baseline-N": "cross-env PRESET=baseline-N MODE=benchmark jest"
"build": "node scripts/jest-foreach.mjs MODE=recorder PRESET=env-1,env-N,no-env-1,no-env-N,bail-env-1,bail-env-N,bail-no-env-1,bail-no-env-N",
"bench": "node scripts/jest-foreach.mjs MODE=benchmark NUM_TESTS=1,10,100,1000,10000 PRESET=metadata-1,metadata-N,fallback-1,fallback-N,baseline-1,baseline-N"
}
}
2 changes: 1 addition & 1 deletion e2e/reporters/recorder.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class E2eRecorderReporter extends JestMetadataReporter {

#pushEvent = (event) => {
const testFilePath = event.testFilePath
? path.relative(cwd, event.testFilePath)
? path.relative(cwd, event.testFilePath).replaceAll(path.win32.sep, path.posix.sep)
: undefined;

const id = testFilePath
Expand Down
42 changes: 42 additions & 0 deletions e2e/scripts/jest-foreach.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/usr/bin/env node

import cp from 'child_process';

// Parsing command line arguments
const argv = process.argv.slice(2);
const params = {};

argv.forEach((arg) => {
const [key, values] = arg.split('=');
params[key] = values.split(',');
});

// Creating permutations
const getPermutations = (arrs) => {
if (arrs.length === 0) return [[]];
const [first, ...rest] = arrs;
const suffixes = getPermutations(rest);
return first.flatMap((value) => suffixes.map((suffix) => [value, ...suffix]));
};

const keys = Object.keys(params);
const values = Object.values(params);
const permutations = getPermutations(values);

// Running Jest with permutations
permutations.forEach((perm) => {
console.log(`${keys.map((k, i) => `${k}=${perm[i]}`).join(' ')} jest`);

try {
cp.execSync(`jest --testFailureExitCode=0`, {
stdio: 'inherit',
env: {
...process.env, // Preserve existing env vars
...Object.fromEntries(keys.map((k, i) => [k, perm[i]])), // Add our custom vars
},
});
} catch (error) {
console.error('Error executing Jest:', error.message);
// Handle error as needed, e.g., exit process, log error, etc.
}
});
4 changes: 3 additions & 1 deletion src/jest-reporter/Shallow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ export const Shallow = {

testResult(testResult: TestResult): TestFileResultArg {
return {
testFilePath: path.relative(process.cwd(), testResult.testFilePath),
testFilePath: path
.relative(process.cwd(), testResult.testFilePath)
.replaceAll(path.win32.sep, path.posix.sep),
testResults: testResult.testResults.map(Shallow.testCaseResult),
};
},
Expand Down

0 comments on commit 70904fe

Please sign in to comment.