chore: improve TS automated type tests (#6860)

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.
This commit is contained in:
Jack Franklin 2021-02-11 10:34:44 +00:00 committed by GitHub
parent bdaba7829d
commit 641ffc2a20
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 33 additions and 13 deletions

3
.gitignore vendored
View File

@ -18,6 +18,5 @@ yarn.lock
/lib
test/coverage.json
temp/
puppeteer-core-*.tgz
new-docs/
puppeteer-*.tgz
puppeteer.tgz

View File

@ -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[]>([
[
@ -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();
@ -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,

View File

@ -7,6 +7,6 @@
"compile": "../../node_modules/.bin/tsc"
},
"dependencies": {
"puppeteer": "file:../../puppeteer-7.0.4-post.tgz"
"puppeteer": "file:../../puppeteer.tgz"
}
}

View File

@ -10,6 +10,6 @@
"typescript": "^4.1.3"
},
"dependencies": {
"puppeteer": "file:../../puppeteer-7.0.4-post.tgz"
"puppeteer": "file:../../puppeteer.tgz"
}
}

View File

@ -10,6 +10,6 @@
"typescript": "^4.1.3"
},
"dependencies": {
"puppeteer": "file:../../puppeteer-7.0.4-post.tgz"
"puppeteer": "file:../../puppeteer.tgz"
}
}

View File

@ -10,6 +10,6 @@
"typescript": "^4.1.3"
},
"dependencies": {
"puppeteer": "file:../../puppeteer-7.0.4-post.tgz"
"puppeteer": "file:../../puppeteer.tgz"
}
}

View File

@ -10,6 +10,6 @@
"typescript": "^4.1.3"
},
"dependencies": {
"puppeteer": "file:../../puppeteer-7.0.4-post.tgz"
"puppeteer": "file:../../puppeteer.tgz"
}
}

View File

@ -10,6 +10,6 @@
"typescript": "^4.1.3"
},
"dependencies": {
"puppeteer": "file:../../puppeteer-7.0.4-post.tgz"
"puppeteer": "file:../../puppeteer.tgz"
}
}

View File

@ -10,6 +10,6 @@
"typescript": "^4.1.3"
},
"dependencies": {
"puppeteer": "file:../../puppeteer-7.0.4-post.tgz"
"puppeteer": "file:../../puppeteer.tgz"
}
}