Skip to content

Commit

Permalink
add retries around npm install in tests on windows
Browse files Browse the repository at this point in the history
  • Loading branch information
cspotcode committed Jun 8, 2021
1 parent 5f30514 commit d6ef8fd
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions src/test/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,20 @@ let { register, create, VERSION, createRepl }: typeof tsNodeTypes = {} as any;

// Pack and install ts-node locally, necessary to test package "exports"
test.beforeAll(async () => {
rimrafSync(join(TEST_DIR, 'node_modules'));
await promisify(childProcessExec)(`npm install`, { cwd: TEST_DIR });
const packageLockPath = join(TEST_DIR, 'package-lock.json');
existsSync(packageLockPath) && unlinkSync(packageLockPath);
const totalTries = process.platform === 'win32' ? 5 : 1;
let tries = 0;
while(true) {
try {
rimrafSync(join(TEST_DIR, 'node_modules'));
await promisify(childProcessExec)(`npm install`, { cwd: TEST_DIR });
const packageLockPath = join(TEST_DIR, 'package-lock.json');
existsSync(packageLockPath) && unlinkSync(packageLockPath);
break;
} catch(e) {
tries++;
if(tries >= totalTries) throw e;
}
}
({ register, create, VERSION, createRepl } = testsDirRequire('ts-node'));
});

Expand Down

0 comments on commit d6ef8fd

Please sign in to comment.