Skip to content

Commit 6de4810

Browse files
committed
Fix mocha tests nested packages in node_modules not using workspaces
1 parent 0ef9404 commit 6de4810

File tree

5 files changed

+82
-11
lines changed

5 files changed

+82
-11
lines changed

.github/workflows/ci.yml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -109,16 +109,9 @@ jobs:
109109
uses: volta-cli/action@v1
110110
with:
111111
node-version: ${{ matrix.node-version }}
112-
113-
# Remove test-packages folder so that we don't leak node_modules between apps
114-
- name: Remove test-packages
115-
run: |
116-
rm -rf test-packages
117112
- name: Yarn Install
118-
working-directory: ./packages/ember-cli-fastboot
119113
run: |
120114
yarn install --ignore-engines --frozen-lockfile
121115
- name: Run Mocha Tests
122116
run: |
123-
npm --version
124117
yarn workspace ember-cli-fastboot test:mocha

jsconfig.json

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,16 @@
1-
{"compilerOptions":{"target":"es6","experimentalDecorators":true},"exclude":["node_modules","bower_components","tmp","vendor",".git","dist"]}
1+
{
2+
"compilerOptions": {
3+
"target": "es6",
4+
"experimentalDecorators": true
5+
},
6+
"exclude": [
7+
"node_modules",
8+
"packages/**/node_modules",
9+
"test-packages/**/node_modules",
10+
"bower_components",
11+
"tmp",
12+
"vendor",
13+
".git",
14+
"dist"
15+
]
16+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/**
2+
* Fix nested packages not using workspace version
3+
* ember-cli-addon-tests will link ember-cli-fastboot and run npm install in the test apps,
4+
* the installation will install fastboot from npm registry rather than workspace version
5+
*/
6+
7+
import path from 'path';
8+
import fs from 'fs-extra';
9+
import { fileURLToPath } from 'url';
10+
import chalk from 'chalk';
11+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
12+
13+
const packagesDir = path.resolve(__dirname, '../../packages');
14+
const nodeModulesDir = path.resolve(__dirname, 'node_modules');
15+
16+
// eslint-disable-next-line no-undef
17+
const shouldRestore = process.argv[2];
18+
if (shouldRestore === '--help' || shouldRestore === '-h') {
19+
console.log(`Usage: node fix-node-modules.mjs [arguments]
20+
Options:
21+
-h, --help print this message
22+
-r, --restore restore node_modules by removing symlinks`);
23+
} else if (shouldRestore === '-r' || shouldRestore === '--restore') {
24+
run(true);
25+
} else {
26+
run(false);
27+
}
28+
29+
function run(shouldRestore) {
30+
['fastboot', 'fastboot-express-middleware'].forEach((packageName) => {
31+
const nodeModulesPackageDir = path.join(nodeModulesDir, packageName);
32+
const workspacesPackageDir = path.resolve(packagesDir, packageName);
33+
if (fs.existsSync(nodeModulesPackageDir)) {
34+
console.log(chalk.blue(`remove ${nodeModulesPackageDir}`));
35+
fs.removeSync(nodeModulesPackageDir);
36+
}
37+
if (!shouldRestore) {
38+
console.log(
39+
chalk.green(
40+
`symlink ${nodeModulesPackageDir} -> ${workspacesPackageDir}`
41+
)
42+
);
43+
fs.symlinkSync(workspacesPackageDir, nodeModulesPackageDir, 'dir');
44+
}
45+
});
46+
}

packages/ember-cli-fastboot/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"lint:js:fix": "eslint . --fix",
2424
"start": "ember serve",
2525
"test": "npm-run-all lint test:*",
26-
"test:mocha": "mocha",
26+
"test:mocha": "node fix-node-modules.mjs && mocha && node fix-node-modules.mjs -r",
2727
"test:ember": "ember test",
2828
"test:precook": "node node_modules/ember-cli-addon-tests/scripts/precook-node-modules.js"
2929
},
@@ -33,7 +33,7 @@
3333
"broccoli-funnel": "^2.0.1",
3434
"broccoli-merge-trees": "^3.0.1",
3535
"broccoli-plugin": "^1.3.1",
36-
"chalk": "^2.4.1",
36+
"chalk": "^4.1.2",
3737
"ember-cli-babel": "^7.26.3",
3838
"ember-cli-htmlbars": "^5.7.1",
3939
"ember-cli-lodash-subset": "2.0.1",
@@ -42,7 +42,7 @@
4242
"fastboot": "3.2.0-beta.2",
4343
"fastboot-express-middleware": "3.2.0-beta.2",
4444
"fastboot-transform": "^0.1.3",
45-
"fs-extra": "^7.0.0",
45+
"fs-extra": "^10.0.0",
4646
"json-stable-stringify": "^1.0.1",
4747
"md5-hex": "^2.0.0",
4848
"recast": "^0.19.1",

yarn.lock

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6372,6 +6372,14 @@ chalk@^4.1.1:
63726372
ansi-styles "^4.1.0"
63736373
supports-color "^7.1.0"
63746374

6375+
chalk@^4.1.2:
6376+
version "4.1.2"
6377+
resolved "https://registry.yarnpkg.com/chalk/-/chalk-4.1.2.tgz#aac4e2b7734a740867aeb16bf02aad556a1e7a01"
6378+
integrity sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==
6379+
dependencies:
6380+
ansi-styles "^4.1.0"
6381+
supports-color "^7.1.0"
6382+
63756383
changelog-filename-regex@^1.1.0:
63766384
version "1.1.2"
63776385
resolved "https://registry.yarnpkg.com/changelog-filename-regex/-/changelog-filename-regex-1.1.2.tgz#19e98e38248cff0c1cf3ae3bf51bfb22c48592d6"
@@ -10335,6 +10343,15 @@ fs-extra@^0.30.0:
1033510343
path-is-absolute "^1.0.0"
1033610344
rimraf "^2.2.8"
1033710345

10346+
fs-extra@^10.0.0:
10347+
version "10.0.0"
10348+
resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-10.0.0.tgz#9ff61b655dde53fb34a82df84bb214ce802e17c1"
10349+
integrity sha512-C5owb14u9eJwizKGdchcDUQeFtlSHHthBk8pbX9Vc1PFZrLombudjDnNns88aYslCyF6IY5SUw3Roz6xShcEIQ==
10350+
dependencies:
10351+
graceful-fs "^4.2.0"
10352+
jsonfile "^6.0.1"
10353+
universalify "^2.0.0"
10354+
1033810355
fs-extra@^4.0.2, fs-extra@^4.0.3:
1033910356
version "4.0.3"
1034010357
resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-4.0.3.tgz#0d852122e5bc5beb453fb028e9c0c9bf36340c94"

0 commit comments

Comments
 (0)