chore: simplify installation tests (#9945)

This commit is contained in:
Alex Rudenko 2023-04-04 19:07:24 +02:00 committed by GitHub
parent 327febe2c9
commit de0cc3245e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 297 additions and 460 deletions

422
package-lock.json generated
View File

@ -68,6 +68,7 @@
"pngjs": "7.0.0",
"prettier": "2.8.4",
"puppeteer": "file:packages/puppeteer",
"rimraf": "3.0.2",
"rollup": "3.18.0",
"semver": "7.3.8",
"sinon": "15.0.1",
@ -1139,41 +1140,6 @@
"node": "^12.13.0 || ^14.15.0 || >=16.0.0"
}
},
"node_modules/@npmcli/move-file/node_modules/glob": {
"version": "7.2.3",
"resolved": "https://registry.npmjs.org/glob/-/glob-7.2.3.tgz",
"integrity": "sha512-nFR0zLpU2YCaRxwoCJvL6UvCH2JFyFVIvwTLsIf21AuHlMskA1hhTdk+LlYJtOlYt9v6dvszD2BGRqBL+iQK9Q==",
"dev": true,
"dependencies": {
"fs.realpath": "^1.0.0",
"inflight": "^1.0.4",
"inherits": "2",
"minimatch": "^3.1.1",
"once": "^1.3.0",
"path-is-absolute": "^1.0.0"
},
"engines": {
"node": "*"
},
"funding": {
"url": "https://github.com/sponsors/isaacs"
}
},
"node_modules/@npmcli/move-file/node_modules/rimraf": {
"version": "3.0.2",
"resolved": "https://registry.npmjs.org/rimraf/-/rimraf-3.0.2.tgz",
"integrity": "sha512-JZkJMZkAGFFPP2YqXZXPbMlMBgsxzE8ILs4lMIX/2o0L9UBw9O/Y3o6wFw/i9YLapcUJWwqbi3kdxIPdC62TIA==",
"dev": true,
"dependencies": {
"glob": "^7.1.3"
},
"bin": {
"rimraf": "bin.js"
},
"funding": {
"url": "https://github.com/sponsors/isaacs"
}
},
"node_modules/@npmcli/node-gyp": {
"version": "3.0.0",
"dev": true,
@ -2402,41 +2368,6 @@
"wrap-ansi": "^7.0.0"
}
},
"node_modules/c8/node_modules/glob": {
"version": "7.2.3",
"resolved": "https://registry.npmjs.org/glob/-/glob-7.2.3.tgz",
"integrity": "sha512-nFR0zLpU2YCaRxwoCJvL6UvCH2JFyFVIvwTLsIf21AuHlMskA1hhTdk+LlYJtOlYt9v6dvszD2BGRqBL+iQK9Q==",
"dev": true,
"dependencies": {
"fs.realpath": "^1.0.0",
"inflight": "^1.0.4",
"inherits": "2",
"minimatch": "^3.1.1",
"once": "^1.3.0",
"path-is-absolute": "^1.0.0"
},
"engines": {
"node": "*"
},
"funding": {
"url": "https://github.com/sponsors/isaacs"
}
},
"node_modules/c8/node_modules/rimraf": {
"version": "3.0.2",
"resolved": "https://registry.npmjs.org/rimraf/-/rimraf-3.0.2.tgz",
"integrity": "sha512-JZkJMZkAGFFPP2YqXZXPbMlMBgsxzE8ILs4lMIX/2o0L9UBw9O/Y3o6wFw/i9YLapcUJWwqbi3kdxIPdC62TIA==",
"dev": true,
"dependencies": {
"glob": "^7.1.3"
},
"bin": {
"rimraf": "bin.js"
},
"funding": {
"url": "https://github.com/sponsors/isaacs"
}
},
"node_modules/c8/node_modules/yargs": {
"version": "16.2.0",
"dev": true,
@ -4028,41 +3959,6 @@
"node": "^10.12.0 || >=12.0.0"
}
},
"node_modules/flat-cache/node_modules/glob": {
"version": "7.2.3",
"resolved": "https://registry.npmjs.org/glob/-/glob-7.2.3.tgz",
"integrity": "sha512-nFR0zLpU2YCaRxwoCJvL6UvCH2JFyFVIvwTLsIf21AuHlMskA1hhTdk+LlYJtOlYt9v6dvszD2BGRqBL+iQK9Q==",
"dev": true,
"dependencies": {
"fs.realpath": "^1.0.0",
"inflight": "^1.0.4",
"inherits": "2",
"minimatch": "^3.1.1",
"once": "^1.3.0",
"path-is-absolute": "^1.0.0"
},
"engines": {
"node": "*"
},
"funding": {
"url": "https://github.com/sponsors/isaacs"
}
},
"node_modules/flat-cache/node_modules/rimraf": {
"version": "3.0.2",
"resolved": "https://registry.npmjs.org/rimraf/-/rimraf-3.0.2.tgz",
"integrity": "sha512-JZkJMZkAGFFPP2YqXZXPbMlMBgsxzE8ILs4lMIX/2o0L9UBw9O/Y3o6wFw/i9YLapcUJWwqbi3kdxIPdC62TIA==",
"dev": true,
"dependencies": {
"glob": "^7.1.3"
},
"bin": {
"rimraf": "bin.js"
},
"funding": {
"url": "https://github.com/sponsors/isaacs"
}
},
"node_modules/flatted": {
"version": "3.2.7",
"dev": true,
@ -4368,26 +4264,6 @@
"typescript": ">=3"
}
},
"node_modules/gts/node_modules/glob": {
"version": "7.2.3",
"resolved": "https://registry.npmjs.org/glob/-/glob-7.2.3.tgz",
"integrity": "sha512-nFR0zLpU2YCaRxwoCJvL6UvCH2JFyFVIvwTLsIf21AuHlMskA1hhTdk+LlYJtOlYt9v6dvszD2BGRqBL+iQK9Q==",
"dev": true,
"dependencies": {
"fs.realpath": "^1.0.0",
"inflight": "^1.0.4",
"inherits": "2",
"minimatch": "^3.1.1",
"once": "^1.3.0",
"path-is-absolute": "^1.0.0"
},
"engines": {
"node": "*"
},
"funding": {
"url": "https://github.com/sponsors/isaacs"
}
},
"node_modules/gts/node_modules/meow": {
"version": "9.0.0",
"dev": true,
@ -4427,21 +4303,6 @@
"url": "https://github.com/prettier/prettier?sponsor=1"
}
},
"node_modules/gts/node_modules/rimraf": {
"version": "3.0.2",
"resolved": "https://registry.npmjs.org/rimraf/-/rimraf-3.0.2.tgz",
"integrity": "sha512-JZkJMZkAGFFPP2YqXZXPbMlMBgsxzE8ILs4lMIX/2o0L9UBw9O/Y3o6wFw/i9YLapcUJWwqbi3kdxIPdC62TIA==",
"dev": true,
"dependencies": {
"glob": "^7.1.3"
},
"bin": {
"rimraf": "bin.js"
},
"funding": {
"url": "https://github.com/sponsors/isaacs"
}
},
"node_modules/gts/node_modules/type-fest": {
"version": "0.18.1",
"dev": true,
@ -5782,63 +5643,6 @@
"node": ">=8"
}
},
"node_modules/make-fetch-happen/node_modules/rimraf": {
"version": "3.0.2",
"resolved": "https://registry.npmjs.org/rimraf/-/rimraf-3.0.2.tgz",
"integrity": "sha512-JZkJMZkAGFFPP2YqXZXPbMlMBgsxzE8ILs4lMIX/2o0L9UBw9O/Y3o6wFw/i9YLapcUJWwqbi3kdxIPdC62TIA==",
"dev": true,
"dependencies": {
"glob": "^7.1.3"
},
"bin": {
"rimraf": "bin.js"
},
"funding": {
"url": "https://github.com/sponsors/isaacs"
}
},
"node_modules/make-fetch-happen/node_modules/rimraf/node_modules/brace-expansion": {
"version": "1.1.11",
"resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz",
"integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==",
"dev": true,
"dependencies": {
"balanced-match": "^1.0.0",
"concat-map": "0.0.1"
}
},
"node_modules/make-fetch-happen/node_modules/rimraf/node_modules/glob": {
"version": "7.2.3",
"resolved": "https://registry.npmjs.org/glob/-/glob-7.2.3.tgz",
"integrity": "sha512-nFR0zLpU2YCaRxwoCJvL6UvCH2JFyFVIvwTLsIf21AuHlMskA1hhTdk+LlYJtOlYt9v6dvszD2BGRqBL+iQK9Q==",
"dev": true,
"dependencies": {
"fs.realpath": "^1.0.0",
"inflight": "^1.0.4",
"inherits": "2",
"minimatch": "^3.1.1",
"once": "^1.3.0",
"path-is-absolute": "^1.0.0"
},
"engines": {
"node": "*"
},
"funding": {
"url": "https://github.com/sponsors/isaacs"
}
},
"node_modules/make-fetch-happen/node_modules/rimraf/node_modules/minimatch": {
"version": "3.1.2",
"resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz",
"integrity": "sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==",
"dev": true,
"dependencies": {
"brace-expansion": "^1.1.7"
},
"engines": {
"node": "*"
}
},
"node_modules/make-fetch-happen/node_modules/ssri": {
"version": "9.0.1",
"dev": true,
@ -6488,21 +6292,6 @@
"url": "https://github.com/sponsors/isaacs"
}
},
"node_modules/node-gyp/node_modules/rimraf": {
"version": "3.0.2",
"resolved": "https://registry.npmjs.org/rimraf/-/rimraf-3.0.2.tgz",
"integrity": "sha512-JZkJMZkAGFFPP2YqXZXPbMlMBgsxzE8ILs4lMIX/2o0L9UBw9O/Y3o6wFw/i9YLapcUJWwqbi3kdxIPdC62TIA==",
"dev": true,
"dependencies": {
"glob": "^7.1.3"
},
"bin": {
"rimraf": "bin.js"
},
"funding": {
"url": "https://github.com/sponsors/isaacs"
}
},
"node_modules/nopt": {
"version": "6.0.0",
"dev": true,
@ -7895,6 +7684,41 @@
"node": ">=0.10.0"
}
},
"node_modules/rimraf": {
"version": "3.0.2",
"resolved": "https://registry.npmjs.org/rimraf/-/rimraf-3.0.2.tgz",
"integrity": "sha512-JZkJMZkAGFFPP2YqXZXPbMlMBgsxzE8ILs4lMIX/2o0L9UBw9O/Y3o6wFw/i9YLapcUJWwqbi3kdxIPdC62TIA==",
"dev": true,
"dependencies": {
"glob": "^7.1.3"
},
"bin": {
"rimraf": "bin.js"
},
"funding": {
"url": "https://github.com/sponsors/isaacs"
}
},
"node_modules/rimraf/node_modules/glob": {
"version": "7.2.3",
"resolved": "https://registry.npmjs.org/glob/-/glob-7.2.3.tgz",
"integrity": "sha512-nFR0zLpU2YCaRxwoCJvL6UvCH2JFyFVIvwTLsIf21AuHlMskA1hhTdk+LlYJtOlYt9v6dvszD2BGRqBL+iQK9Q==",
"dev": true,
"dependencies": {
"fs.realpath": "^1.0.0",
"inflight": "^1.0.4",
"inherits": "2",
"minimatch": "^3.1.1",
"once": "^1.3.0",
"path-is-absolute": "^1.0.0"
},
"engines": {
"node": "*"
},
"funding": {
"url": "https://github.com/sponsors/isaacs"
}
},
"node_modules/rollup": {
"version": "3.18.0",
"dev": true,
@ -10294,31 +10118,6 @@
"requires": {
"mkdirp": "^1.0.4",
"rimraf": "^3.0.2"
},
"dependencies": {
"glob": {
"version": "7.2.3",
"resolved": "https://registry.npmjs.org/glob/-/glob-7.2.3.tgz",
"integrity": "sha512-nFR0zLpU2YCaRxwoCJvL6UvCH2JFyFVIvwTLsIf21AuHlMskA1hhTdk+LlYJtOlYt9v6dvszD2BGRqBL+iQK9Q==",
"dev": true,
"requires": {
"fs.realpath": "^1.0.0",
"inflight": "^1.0.4",
"inherits": "2",
"minimatch": "^3.1.1",
"once": "^1.3.0",
"path-is-absolute": "^1.0.0"
}
},
"rimraf": {
"version": "3.0.2",
"resolved": "https://registry.npmjs.org/rimraf/-/rimraf-3.0.2.tgz",
"integrity": "sha512-JZkJMZkAGFFPP2YqXZXPbMlMBgsxzE8ILs4lMIX/2o0L9UBw9O/Y3o6wFw/i9YLapcUJWwqbi3kdxIPdC62TIA==",
"dev": true,
"requires": {
"glob": "^7.1.3"
}
}
}
},
"@npmcli/node-gyp": {
@ -11250,29 +11049,6 @@
"wrap-ansi": "^7.0.0"
}
},
"glob": {
"version": "7.2.3",
"resolved": "https://registry.npmjs.org/glob/-/glob-7.2.3.tgz",
"integrity": "sha512-nFR0zLpU2YCaRxwoCJvL6UvCH2JFyFVIvwTLsIf21AuHlMskA1hhTdk+LlYJtOlYt9v6dvszD2BGRqBL+iQK9Q==",
"dev": true,
"requires": {
"fs.realpath": "^1.0.0",
"inflight": "^1.0.4",
"inherits": "2",
"minimatch": "^3.1.1",
"once": "^1.3.0",
"path-is-absolute": "^1.0.0"
}
},
"rimraf": {
"version": "3.0.2",
"resolved": "https://registry.npmjs.org/rimraf/-/rimraf-3.0.2.tgz",
"integrity": "sha512-JZkJMZkAGFFPP2YqXZXPbMlMBgsxzE8ILs4lMIX/2o0L9UBw9O/Y3o6wFw/i9YLapcUJWwqbi3kdxIPdC62TIA==",
"dev": true,
"requires": {
"glob": "^7.1.3"
}
},
"yargs": {
"version": "16.2.0",
"dev": true,
@ -12294,31 +12070,6 @@
"requires": {
"flatted": "^3.1.0",
"rimraf": "^3.0.2"
},
"dependencies": {
"glob": {
"version": "7.2.3",
"resolved": "https://registry.npmjs.org/glob/-/glob-7.2.3.tgz",
"integrity": "sha512-nFR0zLpU2YCaRxwoCJvL6UvCH2JFyFVIvwTLsIf21AuHlMskA1hhTdk+LlYJtOlYt9v6dvszD2BGRqBL+iQK9Q==",
"dev": true,
"requires": {
"fs.realpath": "^1.0.0",
"inflight": "^1.0.4",
"inherits": "2",
"minimatch": "^3.1.1",
"once": "^1.3.0",
"path-is-absolute": "^1.0.0"
}
},
"rimraf": {
"version": "3.0.2",
"resolved": "https://registry.npmjs.org/rimraf/-/rimraf-3.0.2.tgz",
"integrity": "sha512-JZkJMZkAGFFPP2YqXZXPbMlMBgsxzE8ILs4lMIX/2o0L9UBw9O/Y3o6wFw/i9YLapcUJWwqbi3kdxIPdC62TIA==",
"dev": true,
"requires": {
"glob": "^7.1.3"
}
}
}
},
"flatted": {
@ -12521,20 +12272,6 @@
"write-file-atomic": "^4.0.0"
},
"dependencies": {
"glob": {
"version": "7.2.3",
"resolved": "https://registry.npmjs.org/glob/-/glob-7.2.3.tgz",
"integrity": "sha512-nFR0zLpU2YCaRxwoCJvL6UvCH2JFyFVIvwTLsIf21AuHlMskA1hhTdk+LlYJtOlYt9v6dvszD2BGRqBL+iQK9Q==",
"dev": true,
"requires": {
"fs.realpath": "^1.0.0",
"inflight": "^1.0.4",
"inherits": "2",
"minimatch": "^3.1.1",
"once": "^1.3.0",
"path-is-absolute": "^1.0.0"
}
},
"meow": {
"version": "9.0.0",
"dev": true,
@ -12557,15 +12294,6 @@
"version": "2.7.1",
"dev": true
},
"rimraf": {
"version": "3.0.2",
"resolved": "https://registry.npmjs.org/rimraf/-/rimraf-3.0.2.tgz",
"integrity": "sha512-JZkJMZkAGFFPP2YqXZXPbMlMBgsxzE8ILs4lMIX/2o0L9UBw9O/Y3o6wFw/i9YLapcUJWwqbi3kdxIPdC62TIA==",
"dev": true,
"requires": {
"glob": "^7.1.3"
}
},
"type-fest": {
"version": "0.18.1",
"dev": true
@ -13427,50 +13155,6 @@
"yallist": "^4.0.0"
}
},
"rimraf": {
"version": "3.0.2",
"resolved": "https://registry.npmjs.org/rimraf/-/rimraf-3.0.2.tgz",
"integrity": "sha512-JZkJMZkAGFFPP2YqXZXPbMlMBgsxzE8ILs4lMIX/2o0L9UBw9O/Y3o6wFw/i9YLapcUJWwqbi3kdxIPdC62TIA==",
"dev": true,
"requires": {
"glob": "^7.1.3"
},
"dependencies": {
"brace-expansion": {
"version": "1.1.11",
"resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz",
"integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==",
"dev": true,
"requires": {
"balanced-match": "^1.0.0",
"concat-map": "0.0.1"
}
},
"glob": {
"version": "7.2.3",
"resolved": "https://registry.npmjs.org/glob/-/glob-7.2.3.tgz",
"integrity": "sha512-nFR0zLpU2YCaRxwoCJvL6UvCH2JFyFVIvwTLsIf21AuHlMskA1hhTdk+LlYJtOlYt9v6dvszD2BGRqBL+iQK9Q==",
"dev": true,
"requires": {
"fs.realpath": "^1.0.0",
"inflight": "^1.0.4",
"inherits": "2",
"minimatch": "^3.1.1",
"once": "^1.3.0",
"path-is-absolute": "^1.0.0"
}
},
"minimatch": {
"version": "3.1.2",
"resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz",
"integrity": "sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==",
"dev": true,
"requires": {
"brace-expansion": "^1.1.7"
}
}
}
},
"ssri": {
"version": "9.0.1",
"dev": true,
@ -13903,15 +13587,6 @@
"once": "^1.3.0",
"path-is-absolute": "^1.0.0"
}
},
"rimraf": {
"version": "3.0.2",
"resolved": "https://registry.npmjs.org/rimraf/-/rimraf-3.0.2.tgz",
"integrity": "sha512-JZkJMZkAGFFPP2YqXZXPbMlMBgsxzE8ILs4lMIX/2o0L9UBw9O/Y3o6wFw/i9YLapcUJWwqbi3kdxIPdC62TIA==",
"dev": true,
"requires": {
"glob": "^7.1.3"
}
}
}
},
@ -14832,6 +14507,31 @@
"version": "1.0.4",
"dev": true
},
"rimraf": {
"version": "3.0.2",
"resolved": "https://registry.npmjs.org/rimraf/-/rimraf-3.0.2.tgz",
"integrity": "sha512-JZkJMZkAGFFPP2YqXZXPbMlMBgsxzE8ILs4lMIX/2o0L9UBw9O/Y3o6wFw/i9YLapcUJWwqbi3kdxIPdC62TIA==",
"dev": true,
"requires": {
"glob": "^7.1.3"
},
"dependencies": {
"glob": {
"version": "7.2.3",
"resolved": "https://registry.npmjs.org/glob/-/glob-7.2.3.tgz",
"integrity": "sha512-nFR0zLpU2YCaRxwoCJvL6UvCH2JFyFVIvwTLsIf21AuHlMskA1hhTdk+LlYJtOlYt9v6dvszD2BGRqBL+iQK9Q==",
"dev": true,
"requires": {
"fs.realpath": "^1.0.0",
"inflight": "^1.0.4",
"inherits": "2",
"minimatch": "^3.1.1",
"once": "^1.3.0",
"path-is-absolute": "^1.0.0"
}
}
}
},
"rollup": {
"version": "3.18.0",
"dev": true,

View File

@ -172,6 +172,7 @@
"pngjs": "7.0.0",
"prettier": "2.8.4",
"puppeteer": "file:packages/puppeteer",
"rimraf": "3.0.2",
"rollup": "3.18.0",
"semver": "7.3.8",
"sinon": "15.0.1",

View File

@ -18,6 +18,4 @@
module.exports = {
spec: ['build/**/*.spec.js'],
timeout: '240000ms',
// Parallel processing fails on other package managers due to caching.
parallel: (process.env['PKG_MANAGER'] ?? 'npm') === 'npm',
};

View File

@ -18,27 +18,31 @@ import assert from 'assert';
import {readdir, writeFile} from 'fs/promises';
import {join} from 'path';
import {describeInstallation} from './describeInstallation.js';
import {configureSandbox} from './sandbox.js';
import {readAsset} from './util.js';
describeInstallation(
'`puppeteer` with configuration',
{
dependencies: ['puppeteer-core', '@puppeteer/browsers', 'puppeteer'],
describe('`puppeteer` with configuration', () => {
configureSandbox({
dependencies: ['@puppeteer/browsers', 'puppeteer-core', 'puppeteer'],
env: cwd => {
return {
PUPPETEER_CACHE_DIR: join(cwd, '.cache', 'puppeteer'),
};
},
before: async cwd => {
await writeFile(
join(cwd, '.puppeteerrc.cjs'),
await readAsset('puppeteer', 'configuration', '.puppeteerrc.cjs')
);
},
},
({itEvaluates}) => {
itEvaluates('properly', async cwd => {
const files = await readdir(join(cwd, '.cache', 'puppeteer'));
});
it('evaluates', async function () {
const files = await readdir(join(this.sandbox, '.cache', 'puppeteer'));
assert.equal(files.length, 1);
assert.equal(files[0], 'chrome');
return readAsset('puppeteer', 'basic.js');
const script = await readAsset('puppeteer', 'basic.js');
await this.runScript(script, 'mjs');
});
});
}
);

View File

@ -14,31 +14,31 @@
* limitations under the License.
*/
import {describeInstallation} from './describeInstallation.js';
import {configureSandbox} from './sandbox.js';
import {readAsset} from './util.js';
describeInstallation(
'`puppeteer-core`',
{dependencies: ['@puppeteer/browsers', 'puppeteer-core']},
({itEvaluates}) => {
itEvaluates('CommonJS', {commonjs: true}, async () => {
return readAsset('puppeteer-core', 'requires.cjs');
describe('`puppeteer-core`', () => {
configureSandbox({
dependencies: ['@puppeteer/browsers', 'puppeteer-core'],
});
itEvaluates('ES modules', async () => {
return readAsset('puppeteer-core', 'imports.js');
it('evaluates CommonJS', async function () {
const script = await readAsset('puppeteer-core', 'requires.cjs');
await this.runScript(script, 'cjs');
});
it('evaluates ES modules', async function () {
const script = await readAsset('puppeteer-core', 'imports.js');
await this.runScript(script, 'mjs');
});
for (const product of ['firefox', 'chrome']) {
itEvaluates(
`\`launch\` for \`${product}\` with a bad \`executablePath\``,
async () => {
return (await readAsset('puppeteer-core', 'launch.js')).replace(
it(`\`launch\` for \`${product}\` with a bad \`executablePath\``, async function () {
const script = (await readAsset('puppeteer-core', 'launch.js')).replace(
'${product}',
product
);
await this.runScript(script, 'mjs');
});
}
);
}
}
);
});

View File

@ -18,12 +18,11 @@ import assert from 'assert';
import {readdir} from 'fs/promises';
import {join} from 'path';
import {describeInstallation} from './describeInstallation.js';
import {configureSandbox} from './sandbox.js';
import {readAsset} from './util.js';
describeInstallation(
'`puppeteer` with Firefox',
{
describe('`puppeteer` with Firefox', () => {
configureSandbox({
dependencies: ['@puppeteer/browsers', 'puppeteer-core', 'puppeteer'],
env: cwd => {
return {
@ -31,18 +30,18 @@ describeInstallation(
PUPPETEER_PRODUCT: 'firefox',
};
},
},
({itEvaluates}) => {
itEvaluates('CommonJS', {commonjs: true}, async cwd => {
const files = await readdir(join(cwd, '.cache', 'puppeteer'));
});
it('evaluates CommonJS', async function () {
const files = await readdir(join(this.sandbox, '.cache', 'puppeteer'));
assert.equal(files.length, 1);
assert.equal(files[0], 'firefox');
return readAsset('puppeteer-core', 'requires.cjs');
const script = await readAsset('puppeteer-core', 'requires.cjs');
await this.runScript(script, 'cjs');
});
itEvaluates('ES modules', async () => {
return readAsset('puppeteer-core', 'imports.js');
it('evaluates ES modules', async function () {
const script = await readAsset('puppeteer-core', 'imports.js');
await this.runScript(script, 'mjs');
});
});
}
);

View File

@ -17,12 +17,11 @@
import {readFile, rm, writeFile} from 'fs/promises';
import {join} from 'path';
import {describeInstallation} from './describeInstallation.js';
import {configureSandbox} from './sandbox.js';
import {execFile, readAsset} from './util.js';
describeInstallation(
'`puppeteer` with Webpack',
{
describe('`puppeteer` with Webpack', () => {
configureSandbox({
dependencies: ['@puppeteer/browsers', 'puppeteer-core', 'puppeteer'],
devDependencies: ['webpack', 'webpack-cli'],
env: cwd => {
@ -30,29 +29,29 @@ describeInstallation(
PUPPETEER_CACHE_DIR: join(cwd, '.cache', 'puppeteer'),
};
},
},
({itEvaluates}) => {
itEvaluates('Webpack bundles', {commonjs: true}, async cwd => {
});
it('evaluates WebPack Bundles', async function () {
// Write a Webpack configuration.
await writeFile(
join(cwd, 'webpack.config.mjs'),
join(this.sandbox, 'webpack.config.mjs'),
await readAsset('puppeteer', 'webpack', 'webpack.config.js')
);
// Write the source code.
await writeFile(
join(cwd, 'index.js'),
join(this.sandbox, 'index.js'),
await readAsset('puppeteer', 'basic.js')
);
// Bundle.
await execFile('npx', ['webpack'], {cwd, shell: true});
await execFile('npx', ['webpack'], {cwd: this.sandbox, shell: true});
// Remove `node_modules` to test independence.
await rm('node_modules', {recursive: true, force: true});
// Read the bundled file.
return await readFile(join(cwd, 'bundle.js'), 'utf-8');
const script = await readFile(join(this.sandbox, 'bundle.js'), 'utf-8');
await this.runScript(script, 'cjs');
});
});
}
);

View File

@ -18,30 +18,29 @@ import assert from 'assert';
import {readdir} from 'fs/promises';
import {join} from 'path';
import {describeInstallation} from './describeInstallation.js';
import {configureSandbox} from './sandbox.js';
import {readAsset} from './util.js';
describeInstallation(
'`puppeteer`',
{
describe('`puppeteer`', () => {
configureSandbox({
dependencies: ['@puppeteer/browsers', 'puppeteer-core', 'puppeteer'],
env: cwd => {
return {
PUPPETEER_CACHE_DIR: join(cwd, '.cache', 'puppeteer'),
};
},
},
({itEvaluates}) => {
itEvaluates('CommonJS', {commonjs: true}, async cwd => {
const files = await readdir(join(cwd, '.cache', 'puppeteer'));
});
it('evaluates CommonJS', async function () {
const files = await readdir(join(this.sandbox, '.cache', 'puppeteer'));
assert.equal(files.length, 1);
assert.equal(files[0], 'chrome');
return readAsset('puppeteer-core', 'requires.cjs');
const script = await readAsset('puppeteer-core', 'requires.cjs');
await this.runScript(script, 'cjs');
});
itEvaluates('ES modules', async () => {
return readAsset('puppeteer-core', 'imports.js');
it('evaluates ES modules', async function () {
const script = await readAsset('puppeteer-core', 'imports.js');
await this.runScript(script, 'mjs');
});
});
}
);

View File

@ -0,0 +1,137 @@
/**
* Copyright 2022 Google Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import crypto from 'crypto';
import {mkdtemp, rm, writeFile} from 'fs/promises';
import {tmpdir} from 'os';
import {join} from 'path';
import {
PUPPETEER_CORE_PACKAGE_PATH,
PUPPETEER_PACKAGE_PATH,
PUPPETEER_BROWSERS_PACKAGE_PATH,
} from './constants.js';
import {execFile} from './util.js';
const PKG_MANAGER = process.env['PKG_MANAGER'] || 'npm';
let ADD_PKG_SUBCOMMAND = 'install';
if (PKG_MANAGER !== 'npm') {
ADD_PKG_SUBCOMMAND = 'add';
}
export interface ItEvaluatesOptions {
commonjs?: boolean;
}
export interface ItEvaluatesFn {
(
title: string,
options: ItEvaluatesOptions,
getScriptContent: (cwd: string) => Promise<string>
): void;
(title: string, getScriptContent: (cwd: string) => Promise<string>): void;
}
export interface SandboxOptions {
dependencies?: string[];
devDependencies?: string[];
/**
* This should be idempotent.
*/
env?: ((cwd: string) => NodeJS.ProcessEnv) | NodeJS.ProcessEnv;
before?: (cwd: string) => Promise<void>;
}
declare module 'mocha' {
export interface Context {
/**
* The path to the root of the sandbox folder.
*/
sandbox: string;
env: NodeJS.ProcessEnv | undefined;
runScript: (content: string, type: 'cjs' | 'mjs') => Promise<void>;
}
}
/**
* Configures mocha before/after hooks to create a temp folder and install
* specified dependencies.
*/
export const configureSandbox = (options: SandboxOptions): void => {
before(async function (): Promise<void> {
const sandbox = await mkdtemp(join(tmpdir(), 'puppeteer-'));
const dependencies = (options.dependencies ?? []).map(module => {
switch (module) {
case 'puppeteer':
return PUPPETEER_PACKAGE_PATH;
case 'puppeteer-core':
return PUPPETEER_CORE_PACKAGE_PATH;
case '@puppeteer/browsers':
return PUPPETEER_BROWSERS_PACKAGE_PATH;
default:
return module;
}
});
const devDependencies = options.devDependencies ?? [];
let getEnv: (cwd: string) => NodeJS.ProcessEnv | undefined;
if (typeof options.env === 'function') {
getEnv = options.env;
} else {
const env = options.env;
getEnv = () => {
return env;
};
}
const env = {...process.env, ...getEnv(sandbox)};
await options.before?.(sandbox);
if (dependencies.length > 0) {
await execFile(PKG_MANAGER, [ADD_PKG_SUBCOMMAND, ...dependencies], {
cwd: sandbox,
env,
shell: true,
});
}
if (devDependencies.length > 0) {
await execFile(
PKG_MANAGER,
[ADD_PKG_SUBCOMMAND, '-D', ...devDependencies],
{
cwd: sandbox,
env,
shell: true,
}
);
}
this.sandbox = sandbox;
this.env = env;
this.runScript = async (content: string, type: 'cjs' | 'mjs') => {
const script = join(sandbox, `script-${crypto.randomUUID()}.${type}`);
await writeFile(script, content);
await execFile('node', [script], {cwd: sandbox, env});
};
});
after(async function () {
if (!process.env['KEEP_SANDBOX']) {
await rm(this.sandbox, {recursive: true, force: true, maxRetries: 5});
} else {
console.log('sandbox saved in', this.sandbox);
}
});
};