Skip to content

Commit 911c750

Browse files
committed
chore(ci): fix nvm error on configuring functional tests npm production environment
1 parent 651d5af commit 911c750

File tree

2 files changed

+54
-20
lines changed

2 files changed

+54
-20
lines changed

.circleci/config.yml

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,6 @@ commands:
116116
## the production mode tests to fail if any of the dependencies is a
117117
## binary dependency that is built using node-gyp.
118118
- run: npm config set python /bin/false
119-
- configure_global_npm
120119
- run:
121120
## (See #1082 for rationale).
122121
name: run functional tests in npm production environment
@@ -149,15 +148,6 @@ commands:
149148
steps:
150149
- run: npm run github-pr-title-lint
151150

152-
# This is required to avoid a `EACCES` when running `npm link` (which is
153-
# executed in the test suite).
154-
configure_global_npm:
155-
description: create custom directory for global npm installs
156-
steps:
157-
# NOTE: keep the following steps compatible with both bash and cmd.exe
158-
- run: cd .. && mkdir .npm-global
159-
- run: npm config set prefix '../.npm-global'
160-
161151
jobs:
162152
build:
163153
<<: *defaults

tests/functional/test.lib.imports.js

Lines changed: 54 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,56 @@ import {
99
withTempDir, fixturesUseAsLibrary,
1010
} from './common';
1111

12-
const npm = shell.which('npm').toString();
13-
const node = shell.which('node').toString();
12+
const npm = shell.which('npm')?.toString();
13+
const node = shell.which('node')?.toString();
14+
const nvm = shell.which('nvm')?.toString();
15+
const isWindows = process.platform === 'win32';
16+
17+
function npmGlobalDir() {
18+
if (!process.env.HOME) {
19+
throw new Error('HOME environment variable is undefined');
20+
}
21+
const npmDir = path.join(
22+
process.env.HOME, '.npm-global'
23+
);
24+
if (!shell.test('-d', npmDir)) {
25+
shell.echo(`Creating test npm directory at ${npmDir}`);
26+
shell.mkdir(npmDir);
27+
}
28+
return npmDir;
29+
}
30+
31+
function npmLink() {
32+
if (nvm || isWindows) {
33+
execFileSync(npm, ['link', '.'], {
34+
cwd: path.resolve(path.join(__dirname, '..', '..')),
35+
});
36+
} else {
37+
execFileSync(npm, ['link', '.'], {
38+
cwd: path.resolve(path.join(__dirname, '..', '..')),
39+
env: {
40+
...process.env,
41+
NPM_CONFIG_PREFIX: npmGlobalDir(),
42+
},
43+
});
44+
}
45+
}
46+
47+
function npmUnlink() {
48+
if (nvm || isWindows) {
49+
execFileSync(npm, ['unlink', '.'], {
50+
cwd: path.resolve(path.join(__dirname, '..', '..')),
51+
});
52+
} else {
53+
execFileSync(npm, ['unlink', '.'], {
54+
cwd: path.resolve(path.join(__dirname, '..', '..')),
55+
env: {
56+
...process.env,
57+
NPM_CONFIG_PREFIX: npmGlobalDir(),
58+
},
59+
});
60+
}
61+
}
1462

1563
describe('web-ext imported as a library', () => {
1664
before(function() {
@@ -21,20 +69,16 @@ describe('web-ext imported as a library', () => {
2169
this.skip();
2270
}
2371

24-
execFileSync(npm, ['link', '.'], {
25-
cwd: path.resolve(path.join(__dirname, '..', '..')),
26-
});
72+
npmLink();
2773
});
2874

2975
after(() => {
30-
execFileSync(npm, ['unlink', '.'], {
31-
cwd: path.resolve(path.join(__dirname, '..', '..')),
32-
});
76+
npmUnlink();
3377
});
3478

3579
it('can be imported as an ESM module', async () => {
3680
await withTempDir(async (tmpDir) => {
37-
execFileSync(npm, ['link', 'web-ext'], {cwd: tmpDir.path()});
81+
execFileSync(npm, ['install', 'web-ext'], {cwd: tmpDir.path()});
3882
shell.cp('-rf', `${fixturesUseAsLibrary}/*`, tmpDir.path());
3983
execFileSync(node, ['--experimental-modules', 'test-import.mjs'], {
4084
cwd: tmpDir.path(),
@@ -44,7 +88,7 @@ describe('web-ext imported as a library', () => {
4488

4589
it('can be imported as a CommonJS module', async () => {
4690
await withTempDir(async (tmpDir) => {
47-
execFileSync(npm, ['link', 'web-ext'], {cwd: tmpDir.path()});
91+
execFileSync(npm, ['install', 'web-ext'], {cwd: tmpDir.path()});
4892
shell.cp('-rf', `${fixturesUseAsLibrary}/*`, tmpDir.path());
4993
execFileSync(node, ['--experimental-modules', 'test-require.js'], {
5094
cwd: tmpDir.path(),

0 commit comments

Comments
 (0)