Skip to content

Commit 5d7b94b

Browse files
committed
Move @web/test-runner config into packages with tests. Combine WTR/WCT test workflows.
1 parent c259aa6 commit 5d7b94b

File tree

8 files changed

+170
-194
lines changed

8 files changed

+170
-194
lines changed

.github/workflows/tests.yml

+4-53
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121
- name: Check formatting
2222
run: npm run format && git diff --exit-code
2323

24-
wct-local:
24+
local:
2525
runs-on: ubuntu-latest
2626

2727
steps:
@@ -39,31 +39,10 @@ jobs:
3939
- name: Build
4040
run: npm run build
4141

42-
- name: WCT local (Chrome/Firefox)
42+
- name: Test
4343
run: npm test
4444

45-
wtr-local:
46-
runs-on: ubuntu-latest
47-
48-
steps:
49-
- uses: actions/checkout@v2
50-
- uses: actions/setup-node@v2
51-
with:
52-
node-version: 16
53-
54-
- name: NPM install
55-
run: npm ci
56-
57-
- name: Lerna bootstrap
58-
run: npm run bootstrap
59-
60-
- name: Build
61-
run: npm run build
62-
63-
- name: WTR local (Chrome/Firefox)
64-
run: BROWSERS=chromium,firefox npm run test:wtr
65-
66-
wct-sauce:
45+
sauce:
6746
# Skip if this is from a forked repository because we can't access Sauce
6847
# secrets.
6948
if: github.event.pull_request.base.repo.id == github.event.pull_request.head.repo.id
@@ -85,36 +64,8 @@ jobs:
8564
- name: Build
8665
run: npm run build
8766

88-
- name: WCT sauce (Safari/Edge/IE11/Chrome 41)
67+
- name: Test
8968
env:
9069
SAUCE_USERNAME: ${{ secrets.SAUCE_USERNAME }}
9170
SAUCE_ACCESS_KEY: ${{ secrets.SAUCE_ACCESS_KEY }}
9271
run: npm run test-sauce
93-
94-
wtr-sauce:
95-
# Skip if this is from a forked repository because we can't access Sauce
96-
# secrets.
97-
if: github.event.pull_request.base.repo.id == github.event.pull_request.head.repo.id
98-
99-
runs-on: ubuntu-latest
100-
101-
steps:
102-
- uses: actions/checkout@v2
103-
- uses: actions/setup-node@v2
104-
with:
105-
node-version: 16
106-
107-
- name: NPM install
108-
run: npm ci
109-
110-
- name: Lerna bootstrap
111-
run: npm run bootstrap
112-
113-
- name: Build
114-
run: npm run build
115-
116-
- name: WTR sauce (Safari/Edge/IE11/Chrome 41)
117-
env:
118-
SAUCE_USERNAME: ${{ secrets.SAUCE_USERNAME }}
119-
SAUCE_ACCESS_KEY: ${{ secrets.SAUCE_ACCESS_KEY }}
120-
run: npm run test:wtr:sauce

package.json

+2-5
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,9 @@
1414
"ignore-sync": "ignore-sync .",
1515
"lint": "eslint \"**/*.{html,js,ts}\"",
1616
"nuke": "rm -rf package-lock.json node_modules && npm install && lerna exec \"rm -f package-lock.json\" && lerna clean --yes && lerna bootstrap && lerna exec --stream -- \"test -f package-lock.json || npm install --package-lock-only\"",
17-
"test": "npm run test:wct",
17+
"test": "wct && lerna run test --stream --ignore @webcomponents/scoped-custom-element-registry",
1818
"test-pack": "lerna exec \"npm pack\"",
19-
"test-sauce": "wct -s 'windows 10/microsoftedge@17' -s 'windows 10/microsoftedge@15' -s 'windows 8.1/internet explorer@11' -s 'macos 10.13/safari@12' -s 'macos 10.13/safari@11' -s 'os x 10.11/safari@10' -s 'os x 10.11/safari@9' -s 'Linux/chrome@41'",
20-
"test:wct": "wct",
21-
"test:wtr": "web-test-runner",
22-
"test:wtr:sauce": "web-test-runner --config web-test-runner-sauce.config.js"
19+
"test-sauce": "wct -s 'windows 10/microsoftedge@17' -s 'windows 10/microsoftedge@15' -s 'windows 8.1/internet explorer@11' -s 'macos 10.13/safari@12' -s 'macos 10.13/safari@11' -s 'os x 10.11/safari@10' -s 'os x 10.11/safari@9' -s 'Linux/chrome@41' && npx lerna run test-sauce --stream --ignore @webcomponents/scoped-custom-element-registry"
2320
},
2421
"devDependencies": {
2522
"@gulp-sourcemaps/sources-content": "^1.0.0",

packages/scoped-custom-element-registry/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"main": "scoped-custom-element-registry.min.js",
2020
"scripts": {
2121
"build": "gulp",
22-
"test": "cd ../.. && wtr 'packages/scoped-custom-element-registry/test/**/*.test.(js|html)'"
22+
"test": "web-test-runner"
2323
},
2424
"files": [
2525
"CHANGELOG.md",

web-test-runner.config.js packages/scoped-custom-element-registry/web-test-runner.config.js

+1-4
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,7 @@ const envBrowsers = process.env.BROWSERS?.split(',').map((product) =>
1313
const browsers = envBrowsers ?? defaultBrowsers;
1414

1515
module.exports = {
16-
files: [
17-
'packages/scoped-custom-element-registry/test/**/*.test.(js|html)',
18-
'packages/tests/custom-elements/html/**/*.test.(js|html)',
19-
],
16+
files: ['test/**/*.test.(js|html)'],
2017
nodeResolve: true,
2118
concurrency: 10,
2219
browsers,
File renamed without changes.

packages/tests/package.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
"private": true,
44
"scripts": {
55
"build": "gulp --gulpfile ./shadycss/gulpfile.js && rollup --config rollup.config.js",
6-
"build:watch": "chokidar --initial --follow-symlinks 'shadycss/module/**/*.js' --ignore 'shadycss/module/generated/**/*' 'node_modules/@webcomponents/shadycss/**/*.js' -c 'npm run build'"
6+
"build:watch": "chokidar --initial --follow-symlinks 'shadycss/module/**/*.js' --ignore 'shadycss/module/generated/**/*' 'node_modules/@webcomponents/shadycss/**/*.js' -c 'npm run build'",
7+
"test": "web-test-runner --group local",
8+
"test-sauce": "web-test-runner --group sauce"
79
},
810
"devDependencies": {
911
"@rollup/plugin-commonjs": "^21.1.0",
+159
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
const {playwrightLauncher} = require('@web/test-runner-playwright');
2+
const {createSauceLabsLauncher} = require('@web/test-runner-saucelabs');
3+
const {compileJSPlugin} = require('./compile-js-plugin.js');
4+
5+
const generateLocalBrowserLaunchers = () => {
6+
const defaultBrowsers = [
7+
playwrightLauncher({product: 'chromium'}),
8+
playwrightLauncher({product: 'webkit'}),
9+
playwrightLauncher({product: 'firefox', concurrency: 1}),
10+
];
11+
12+
const envBrowsers = process.env.BROWSERS?.split(',').map((product) =>
13+
playwrightLauncher({product})
14+
);
15+
16+
return envBrowsers ?? defaultBrowsers;
17+
};
18+
19+
const generateSauceBrowserLaunchers = () => {
20+
const sauceLabsLauncher = createSauceLabsLauncher(
21+
{
22+
user: process.env.SAUCE_USERNAME,
23+
key: process.env.SAUCE_ACCESS_KEY,
24+
},
25+
{
26+
name: 'Polyfills tests',
27+
build: process.env.GITHUB_REF ?? 'local',
28+
}
29+
);
30+
31+
const defaultBrowsers = [
32+
// These browsers support the standard W3C WebDriver protocol.
33+
34+
sauceLabsLauncher({
35+
platformName: 'windows 10',
36+
browserName: 'microsoftedge',
37+
browserVersion: '17',
38+
}),
39+
sauceLabsLauncher({
40+
platformName: 'windows 10',
41+
browserName: 'microsoftedge',
42+
browserVersion: '15',
43+
}),
44+
sauceLabsLauncher({
45+
platformName: 'windows 8.1',
46+
browserName: 'internet explorer',
47+
browserVersion: '11',
48+
}),
49+
sauceLabsLauncher({
50+
platformName: 'macos 10.13',
51+
browserName: 'safari',
52+
browserVersion: '12',
53+
}),
54+
55+
// These browsers only support the older JWP protocol.
56+
//
57+
// Sauce Labs determines which protocol to use to talk to the launched
58+
// browser based on whether or not an option called `sauce:options` exists
59+
// in the given configuration. If this key is passed, the newer W3C standard
60+
// WebDriver protocol is used; otherwise, JWP is used.[^1]
61+
// `@web/test-runner-saucelabs` adds the `sauce:options` key if it sees the
62+
// `browserVersion` key, which is only supported by Sauce Labs with the
63+
// standard WebDriver protocol.[^2] So, we use the older key names here so
64+
// that JWP will be used with these browsers.
65+
//
66+
// [^1]: https://docs.saucelabs.com/dev/w3c-webdriver-capabilities/#use-sauceoptions
67+
// [^2]: https://github.com/modernweb-dev/web/blob/db4949ece675d9c6e4bb722bb9700347258b7e96/packages/test-runner-saucelabs/src/createSauceLabsLauncher.ts#L51-L72
68+
69+
sauceLabsLauncher({
70+
platform: 'macos 10.13',
71+
browserName: 'safari',
72+
version: '11',
73+
}),
74+
sauceLabsLauncher({
75+
platform: 'os x 10.11',
76+
browserName: 'safari',
77+
version: '10',
78+
}),
79+
sauceLabsLauncher({
80+
platform: 'os x 10.11',
81+
browserName: 'safari',
82+
version: '9',
83+
}),
84+
sauceLabsLauncher({
85+
platform: 'Linux',
86+
browserName: 'chrome',
87+
version: '41',
88+
}),
89+
];
90+
91+
/**
92+
* Parses a string representing a browser and platform combination into an
93+
* object with `platformName`, `browserName`, and `browserVersion` properties.
94+
*/
95+
const parseCapabilities = (capabilities) => {
96+
const [platformName, rest] = capabilities.split('/');
97+
const [browserName, browserVersion] = rest.split('@');
98+
return {
99+
platformName,
100+
browserName,
101+
browserVersion,
102+
};
103+
};
104+
105+
// If set, the `BROWSERS` environment variable overrides browsers in the
106+
// `defaultBrowsers` object. Add `;protocol=w3c` or `;protocol=jwp` to a
107+
// browser to explicitly control which protocol is used to control that
108+
// browser.
109+
const envBrowsers = process.env.BROWSERS?.split(',').map((browser) => {
110+
const [capabilities, paramStr] = browser.split(';');
111+
const params = new URLSearchParams(paramStr);
112+
const {platformName, browserName, browserVersion} = parseCapabilities(
113+
capabilities
114+
);
115+
116+
const protocol = params.get('protocol');
117+
if (!protocol || protocol === 'w3c') {
118+
return sauceLabsLauncher({
119+
platformName,
120+
browserName,
121+
browserVersion,
122+
});
123+
} else if (protocol === 'jwp') {
124+
return sauceLabsLauncher({
125+
platform: platformName,
126+
browserName,
127+
version: browserVersion,
128+
});
129+
} else {
130+
console.error('`protocol` must be either undefined, "w3c", or "jwp".');
131+
process.exit(1);
132+
}
133+
});
134+
135+
return envBrowsers ?? defaultBrowsers;
136+
};
137+
138+
module.exports = {
139+
files: ['custom-elements/html/**/*.test.(js|html)'],
140+
rootDir: '../..',
141+
nodeResolve: true,
142+
groups: [
143+
{
144+
name: 'local',
145+
get browsers() {
146+
return generateLocalBrowserLaunchers();
147+
},
148+
},
149+
{
150+
name: 'sauce',
151+
concurrency: 1,
152+
concurrentBrowsers: 1,
153+
get browsers() {
154+
return generateSauceBrowserLaunchers();
155+
},
156+
plugins: [compileJSPlugin()],
157+
},
158+
],
159+
};

0 commit comments

Comments
 (0)