mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
feat: add web test runner (#6200)
This commit is contained in:
parent
13f8fe6e16
commit
15d1906e7c
@ -11,3 +11,4 @@ lib/
|
|||||||
# in the Puppeteer src, so it trips up the ESLint-TypeScript parser.
|
# in the Puppeteer src, so it trips up the ESLint-TypeScript parser.
|
||||||
utils/doclint/generate_types/test/test.ts
|
utils/doclint/generate_types/test/test.ts
|
||||||
vendor/
|
vendor/
|
||||||
|
web-test-runner.config.mjs
|
||||||
|
11
.eslintrc.js
11
.eslintrc.js
@ -125,6 +125,17 @@ module.exports = {
|
|||||||
"default": "array-simple"
|
"default": "array-simple"
|
||||||
}]
|
}]
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"files": ["test-browser/**/*.js"],
|
||||||
|
"parserOptions": {
|
||||||
|
"sourceType": "module"
|
||||||
|
},
|
||||||
|
"env": {
|
||||||
|
"es6": true,
|
||||||
|
"browser": true,
|
||||||
|
"es2020": true
|
||||||
|
},
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
};
|
};
|
||||||
|
@ -57,6 +57,13 @@ jobs:
|
|||||||
script:
|
script:
|
||||||
- travis_retry npm run unit
|
- travis_retry npm run unit
|
||||||
|
|
||||||
|
- node_js: "12.16.3"
|
||||||
|
name: 'Browser tests: Linux/Chromium'
|
||||||
|
env:
|
||||||
|
- CHROMIUM=true
|
||||||
|
script:
|
||||||
|
- travis_retry npm run test-browser
|
||||||
|
|
||||||
# This bot runs all the extra checks that aren't the main Puppeteer unit tests
|
# This bot runs all the extra checks that aren't the main Puppeteer unit tests
|
||||||
- node_js: "10.19.0"
|
- node_js: "10.19.0"
|
||||||
name: 'Extra tests: Linux/Chromium'
|
name: 'Extra tests: Linux/Chromium'
|
||||||
|
@ -8,12 +8,14 @@
|
|||||||
"node": ">=10.18.1"
|
"node": ">=10.18.1"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
"test-browser": "wtr",
|
||||||
|
"test-browser-watch": "wtr --watch",
|
||||||
"unit": "npm run tsc-cjs && mocha --config mocha-config/puppeteer-unit-tests.js",
|
"unit": "npm run tsc-cjs && mocha --config mocha-config/puppeteer-unit-tests.js",
|
||||||
"unit-with-coverage": "cross-env COVERAGE=1 npm run unit",
|
"unit-with-coverage": "cross-env COVERAGE=1 npm run unit",
|
||||||
"assert-unit-coverage": "cross-env COVERAGE=1 mocha --config mocha-config/coverage-tests.js",
|
"assert-unit-coverage": "cross-env COVERAGE=1 mocha --config mocha-config/coverage-tests.js",
|
||||||
"funit": "PUPPETEER_PRODUCT=firefox npm run unit",
|
"funit": "PUPPETEER_PRODUCT=firefox npm run unit",
|
||||||
"debug-unit": "node --inspect-brk test/test.js",
|
"debug-unit": "node --inspect-brk test/test.js",
|
||||||
"test": "npm run tsc && npm run lint --silent && npm run unit-with-coverage && npm run test-types",
|
"test": "npm run tsc && npm run lint --silent && npm run unit-with-coverage && npm run test-browser && npm run test-types",
|
||||||
"prepare": "node typescript-if-required.js",
|
"prepare": "node typescript-if-required.js",
|
||||||
"prepublishOnly": "npm run tsc",
|
"prepublishOnly": "npm run tsc",
|
||||||
"dev-install": "npm run tsc && node install.js",
|
"dev-install": "npm run tsc && node install.js",
|
||||||
@ -69,6 +71,7 @@
|
|||||||
"@types/ws": "^7.2.4",
|
"@types/ws": "^7.2.4",
|
||||||
"@typescript-eslint/eslint-plugin": "^2.28.0",
|
"@typescript-eslint/eslint-plugin": "^2.28.0",
|
||||||
"@typescript-eslint/parser": "^2.28.0",
|
"@typescript-eslint/parser": "^2.28.0",
|
||||||
|
"@web/test-runner": "^0.6.40",
|
||||||
"commonmark": "^0.28.1",
|
"commonmark": "^0.28.1",
|
||||||
"cross-env": "^5.0.5",
|
"cross-env": "^5.0.5",
|
||||||
"dependency-cruiser": "^9.7.0",
|
"dependency-cruiser": "^9.7.0",
|
||||||
|
65
test-browser/debug.spec.js
Normal file
65
test-browser/debug.spec.js
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
/**
|
||||||
|
* Copyright 2020 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 { debug } from '../lib/esm/puppeteer/common/Debug.js';
|
||||||
|
import expect from '../node_modules/expect/build-es5/index.js';
|
||||||
|
|
||||||
|
describe('debug', () => {
|
||||||
|
let originalLog;
|
||||||
|
let logs;
|
||||||
|
beforeEach(() => {
|
||||||
|
originalLog = console.log;
|
||||||
|
logs = [];
|
||||||
|
console.log = (...args) => {
|
||||||
|
logs.push(args);
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
console.log = originalLog;
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return a function', async () => {
|
||||||
|
expect(debug('foo')).toBeInstanceOf(Function);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('does not log to the console if __PUPPETEER_DEBUG global is not set', async () => {
|
||||||
|
const debugFn = debug('foo');
|
||||||
|
debugFn('lorem', 'ipsum');
|
||||||
|
|
||||||
|
expect(logs.length).toEqual(0);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('logs to the console if __PUPPETEER_DEBUG global is set to *', async () => {
|
||||||
|
globalThis.__PUPPETEER_DEBUG = '*';
|
||||||
|
const debugFn = debug('foo');
|
||||||
|
debugFn('lorem', 'ipsum');
|
||||||
|
|
||||||
|
expect(logs.length).toEqual(1);
|
||||||
|
expect(logs).toEqual([['foo:', 'lorem', 'ipsum']]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('logs only messages matching the __PUPPETEER_DEBUG prefix', async () => {
|
||||||
|
globalThis.__PUPPETEER_DEBUG = 'foo';
|
||||||
|
const debugFoo = debug('foo');
|
||||||
|
const debugBar = debug('bar');
|
||||||
|
debugFoo('a');
|
||||||
|
debugBar('b');
|
||||||
|
|
||||||
|
expect(logs.length).toEqual(1);
|
||||||
|
expect(logs).toEqual([['foo:', 'a']]);
|
||||||
|
});
|
||||||
|
});
|
30
web-test-runner.config.js
Normal file
30
web-test-runner.config.js
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
/**
|
||||||
|
* Copyright 2020 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
files: ['test-browser/**/*.spec.js'],
|
||||||
|
plugins: [
|
||||||
|
{
|
||||||
|
// turn expect UMD into an es module
|
||||||
|
name: 'esmify-expect',
|
||||||
|
transform(context) {
|
||||||
|
if (context.path === '/node_modules/expect/build-es5/index.js') {
|
||||||
|
return `const module = {}; const exports = {};\n${context.body};\n export default module.exports;`;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
};
|
Loading…
Reference in New Issue
Block a user