Skip to content

Commit

Permalink
chore: improve TS automated type tests (#6860)
Browse files Browse the repository at this point in the history
This PR:

1. Makes sure we remove and freshly install Puppeteer before testing our
   type defs, to avoid running on stale files.
2. Makes the tests run off `puppeteer.tgz` to avoid having version
   numbers in the file name and therefore having to update it when we
   bump versions.
  • Loading branch information
jackfranklin committed Feb 11, 2021
1 parent bdaba78 commit 641ffc2
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 13 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,5 @@ yarn.lock
/lib
test/coverage.json
temp/
puppeteer-core-*.tgz
new-docs/
puppeteer-*.tgz
puppeteer.tgz
29 changes: 25 additions & 4 deletions scripts/test-ts-definition-files.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { spawnSync } from 'child_process';
import { version } from '../package.json';
import path from 'path';
import fs from 'fs';
const PROJECT_FOLDERS_ROOT = 'test-ts-types';
const EXPECTED_ERRORS = new Map<string, string[]>([
[
Expand Down Expand Up @@ -71,13 +72,23 @@ function packPuppeteer() {
const result = spawnSync('npm', ['pack'], {
encoding: 'utf-8',
});

if (result.status !== 0) {
console.log('Failed to pack Puppeteer', result.stderr);
process.exit(1);
}

return `puppeteer-${version}.tgz`;
// Move from puppeteer-X.Y.Z.tgz to puppeteer.tgz so we don't have to update
// it when versions change.
const moveResult = spawnSync('mv', [
`puppeteer-${version}.tgz`,
'puppeteer.tgz',
]);
if (moveResult.status !== 0) {
console.log('Failed to rename Puppeteer tar', moveResult.stderr);
process.exit(1);
}

return `puppeteer.tgz`;
}

const tar = packPuppeteer();
Expand Down Expand Up @@ -112,12 +123,22 @@ function testProject(folder: string) {
);

const tarLocation = path.relative(projectLocation, tarPath);
console.log('===> Installing Puppeteer from tar file');
console.log('===> Clearing left over node_modules to ensure clean slate');
try {
fs.rmdirSync(path.join(projectLocation, 'node_modules'), {
recursive: true,
});
} catch (_error) {
// We don't care if this errors because if it did it's most likely because
// there was no node_modules folder, which is fine.
}
console.log('===> Installing Puppeteer from tar file', tarLocation);
const { status, stderr, stdout } = spawnSync(
'npm',
['install', '--no-package-lock', tarLocation],
['install', tarLocation],
{
env: {
...process.env,
PUPPETEER_SKIP_DOWNLOAD: '1',
},
cwd: projectLocation,
Expand Down
2 changes: 1 addition & 1 deletion test-ts-types/js-cjs-import-cjs-output/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
"compile": "../../node_modules/.bin/tsc"
},
"dependencies": {
"puppeteer": "file:../../puppeteer-7.0.4-post.tgz"
"puppeteer": "file:../../puppeteer.tgz"
}
}
2 changes: 1 addition & 1 deletion test-ts-types/js-cjs-import-esm-output/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
"typescript": "^4.1.3"
},
"dependencies": {
"puppeteer": "file:../../puppeteer-7.0.4-post.tgz"
"puppeteer": "file:../../puppeteer.tgz"
}
}
2 changes: 1 addition & 1 deletion test-ts-types/js-esm-import-cjs-output/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
"typescript": "^4.1.3"
},
"dependencies": {
"puppeteer": "file:../../puppeteer-7.0.4-post.tgz"
"puppeteer": "file:../../puppeteer.tgz"
}
}
2 changes: 1 addition & 1 deletion test-ts-types/js-esm-import-esm-output/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
"typescript": "^4.1.3"
},
"dependencies": {
"puppeteer": "file:../../puppeteer-7.0.4-post.tgz"
"puppeteer": "file:../../puppeteer.tgz"
}
}
2 changes: 1 addition & 1 deletion test-ts-types/ts-cjs-import-cjs-output/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
"typescript": "^4.1.3"
},
"dependencies": {
"puppeteer": "file:../../puppeteer-7.0.4-post.tgz"
"puppeteer": "file:../../puppeteer.tgz"
}
}
2 changes: 1 addition & 1 deletion test-ts-types/ts-esm-import-cjs-output/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
"typescript": "^4.1.3"
},
"dependencies": {
"puppeteer": "file:../../puppeteer-7.0.4-post.tgz"
"puppeteer": "file:../../puppeteer.tgz"
}
}
2 changes: 1 addition & 1 deletion test-ts-types/ts-esm-import-esm-output/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
"typescript": "^4.1.3"
},
"dependencies": {
"puppeteer": "file:../../puppeteer-7.0.4-post.tgz"
"puppeteer": "file:../../puppeteer.tgz"
}
}

0 comments on commit 641ffc2

Please sign in to comment.