Skip to content

Commit d54463f

Browse files
authored
chore(ci): Debug why jest tests sometimes can't find preset (#382)
1 parent 9161f31 commit d54463f

File tree

2 files changed

+67
-14
lines changed

2 files changed

+67
-14
lines changed

.github/workflows/cli-smoke-tests.yml

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,31 @@ jobs:
4040
working-directory: ${{ steps.set-up-test-project.outputs.test-project-path }}
4141

4242
- name: Run "rw test api"
43-
run: yarn rw test api --no-watch
43+
# Having a bunch of `ls` statements here to see if I can spot anything
44+
# weird looking when this step fails
45+
run: |
46+
echo ""
47+
echo "# ls /"
48+
ls ${{ steps.set-up-test-project.outputs.test-project-path }}/node_modules/@cedarjs/testing
49+
echo ""
50+
echo "# ls /config"
51+
ls ${{ steps.set-up-test-project.outputs.test-project-path }}/node_modules/@cedarjs/testing/config
52+
echo ""
53+
echo "# ls /config/jest"
54+
ls ${{ steps.set-up-test-project.outputs.test-project-path }}/node_modules/@cedarjs/testing/config/jest
55+
echo ""
56+
echo "# ls /config/jest/api"
57+
ls ${{ steps.set-up-test-project.outputs.test-project-path }}/node_modules/@cedarjs/testing/config/jest/api
58+
echo ""
59+
echo "# cat /package.json"
60+
cat ${{ steps.set-up-test-project.outputs.test-project-path }}/node_modules/@cedarjs/testing/package.json && echo ""
61+
echo ""
62+
echo "# cat /config/jest/api/package.json"
63+
cat ${{ steps.set-up-test-project.outputs.test-project-path }}/node_modules/@cedarjs/testing/config/jest/api/package.json && echo ""
64+
echo ""
65+
echo ""
66+
echo "# Starting test"
67+
yarn rw test api --no-watch
4468
working-directory: ${{ steps.set-up-test-project.outputs.test-project-path }}
4569

4670
- name: Run "rw test web"

packages/testing/build.mts

Lines changed: 42 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -34,21 +34,50 @@ fs.rmSync('./config', { recursive: true, force: true })
3434
fs.mkdirSync('./config')
3535
fs.cpSync('./dist/cjs/config', './config', { recursive: true })
3636
fs.cpSync('./dist/cjs/package.json', './config/package.json')
37-
// Some background on the two `fs.cpSync` calls below: I've been having problems
38-
// with jest testing in CI sometimes failing to find the jest preset file. I
39-
// don't know why. But after deep-diving into the jest source code I realized it
40-
// was looking for a package.json in the same directory as it first tries to
41-
// find the preset. It's supposed to traverse up the folder tree if it can't
42-
// find one, until it does. I'm not sure if this is sometimes failing, or what
43-
// happens when it finds one much further up the tree. Maybe jest then tries to
44-
// resolve the preset in *that* directory. Anyway, to make things as easy for it
45-
// as possible, I updated the testing package build script to put a package.json
46-
// files in the preset directories for both the api and the web sides. And after
47-
// that CI passed.
37+
38+
// Some background on the package.json related commands below: I've been having
39+
// problems with jest testing in CI sometimes failing to find the jest preset
40+
// file. I don't know why. But after deep-diving into the jest source code I
41+
// realized it was looking for a package.json in the same directory as it first
42+
// tries to find the preset. It's supposed to traverse up the folder tree if it
43+
// can't find one, until it does. I'm not sure if this is sometimes failing, or
44+
// what happens when it finds one much further up the tree. Maybe jest then
45+
// tries to resolve the preset in *that* directory. Anyway, to make things as
46+
// easy for it as possible, I updated the testing package build script to put a
47+
// package.json files in the preset directories for both the api and the web
48+
// sides. And after that CI passed.
4849
// But since it's been flakey I don't know if this was the actual fix, or if it
4950
// just randomly decided to pass.
50-
fs.cpSync('./dist/cjs/package.json', './config/jest/api/package.json')
51-
fs.cpSync('./dist/cjs/package.json', './config/jest/web/package.json')
51+
fs.writeFileSync(
52+
'./config/jest/api/package.json',
53+
JSON.stringify(
54+
{
55+
name: 'cedarjs-jest-api-preset',
56+
version: '0.0.1',
57+
type: 'commonjs',
58+
main: 'index.js',
59+
license: 'MIT',
60+
types: './index.d.ts',
61+
},
62+
null,
63+
2,
64+
),
65+
)
66+
fs.writeFileSync(
67+
'./config/jest/web/package.json',
68+
JSON.stringify(
69+
{
70+
name: 'cedarjs-jest-web-preset',
71+
version: '0.0.1',
72+
type: 'commonjs',
73+
main: 'index.js',
74+
license: 'MIT',
75+
types: './index.d.ts',
76+
},
77+
null,
78+
2,
79+
),
80+
)
5281

5382
// Replace relative imports with absolute @cedarjs/testing/dist/cjs imports in built CJS files
5483
function replaceImportsInFile(filePath: string) {

0 commit comments

Comments
 (0)