Skip to content

Commit c9d0c14

Browse files
authored
Support cjs/mjs config files (#203)
* make internal pw config explicitly cjs * Convert base config to esm * Use fully qualified, platform specific absolute path for import * More succinctly * Run basic-ts and config-merging in testing workflow * Make the basic-ts test explicitly ESM * move test specific gitignore to test dir root * cleanup * cleanup unused files * fix gitignore * powershell-ify * setup github token for saucectl action * make config source mjs * rename file
1 parent f39e110 commit c9d0c14

File tree

13 files changed

+48
-107
lines changed

13 files changed

+48
-107
lines changed

.github/workflows/test.yml

+24-3
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@ jobs:
4444
uses: actions/checkout@v3
4545

4646
- name: Setup saucectl
47-
uses: saucelabs/saucectl-run-action@v2
47+
uses: saucelabs/saucectl-run-action@v3
48+
env:
49+
GITHUB_TOKEN: ${{ github.token }}
4850
with:
4951
skip-run: true
5052

@@ -80,10 +82,29 @@ jobs:
8082
npx playwright install
8183
npx playwright install-deps
8284
83-
- run: node . --suiteName basic-js --runCfgPath ./tests/fixtures/local/basic-js/sauce-runner.json
85+
- name: Run basic-js
86+
run: |
87+
node . `
88+
--suiteName basic-js `
89+
--runCfgPath ./tests/fixtures/local/basic-js/sauce-runner.json
90+
env:
91+
SAUCE_VM: true
92+
93+
- name: Run basic-ts
94+
run: |
95+
node . `
96+
--suiteName basic-ts `
97+
--runCfgPath ./tests/fixtures/local/basic-ts/sauce-runner.json
98+
env:
99+
SAUCE_VM: true
100+
101+
- name: Run config-merging
102+
run: |
103+
node . `
104+
--suiteName config-merging `
105+
--runCfgPath ./tests/fixtures/local/config-merging/sauce-runner.json
84106
env:
85107
SAUCE_VM: true
86-
name: Run test locally
87108

88109
cucumber-build-and-test-local:
89110
runs-on: windows-latest

src/playwright-runner.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -374,8 +374,8 @@ async function runPlaywright(nodeBin, runCfg) {
374374

375375
// Copy our runner's playwright config to a custom location in order to
376376
// preserve the customer's config which we may want to load in the future
377-
const configFile = path.join(runCfg.projectPath, 'sauce.config.js');
378-
fs.copyFileSync(path.join(__dirname, 'sauce.config.js'), configFile);
377+
const configFile = path.join(runCfg.projectPath, 'sauce.config.mjs');
378+
fs.copyFileSync(path.join(__dirname, 'sauce.config.mjs'), configFile);
379379

380380
const defaultArgs = {
381381
output: runCfg.playwrightOutputFolder,

src/sauce.config.js renamed to src/sauce.config.mjs

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
const process = require('process');
2-
const _ = require('lodash');
3-
const fs = require('fs');
1+
import * as fs from 'node:fs';
2+
import * as process from 'node:process';
3+
import { pathToFileURL } from 'node:url';
4+
import _ from 'lodash';
45

56
let userConfig = {};
67

@@ -12,7 +13,7 @@ const configFiles = process.env.PLAYWRIGHT_CFG_FILE ?
1213
for (const file of configFiles) {
1314
if (fs.existsSync(file)) {
1415
try {
15-
userConfig = require(file);
16+
userConfig = await import(pathToFileURL(file));
1617
// it should put config just under root level to get it work with playwright.config.ts
1718
// there is no such issue with playwright.config.js
1819
if (userConfig.default) {
@@ -80,4 +81,4 @@ function arrMerger(objValue, srcValue) {
8081
}
8182
}
8283

83-
module.exports = _.mergeWith(userConfig, overrides, arrMerger);
84+
export default _.mergeWith(userConfig, overrides, arrMerger);

tests/fixtures/local/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
sauce.config.*js

tests/fixtures/local/basic-js/sauce.config.js

-83
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"type": "module"
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { defineConfig } from '@playwright/test';
2+
3+
export default defineConfig({
4+
use: {
5+
headless: true,
6+
video: 'on',
7+
},
8+
});

tests/fixtures/local/basic-ts/sauce-runner.json

+2-3
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,9 @@
77
"name": "basic-ts",
88
"param": {
99
"browserName": "chromium",
10-
"headful": true,
11-
"slowMo": 10000
10+
"headless": true
1211
},
1312
"testMatch": ".*.spec.ts"
1413
}
1514
]
16-
}
15+
}

tests/fixtures/local/config-merging/.gitignore

-1
This file was deleted.

tests/fixtures/local/config-merging/playwright.config.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@
22
module.exports = {
33
use: {
44
headless: true,
5-
video: false,
5+
video: 'off',
66
timezoneId: 'Asia/Seoul',
77
locale: 'ko-KR',
88
reporter: [['dot']],
99
},
1010
};
11-

tests/fixtures/local/config-merging/sauce-runner.json

+1-8
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,7 @@
1414
{
1515
"name": "config-merging",
1616
"param": {
17-
"browserName": "chromium",
18-
"globalTimeout": 900000,
19-
"grep": ".*",
20-
"repeatEach": 1,
21-
"retries": 0,
22-
"shard": "1/2",
23-
"timeout": 30000,
24-
"maxFailures": 2
17+
"browserName": "chromium"
2518
},
2619
"testMatch": ".*.js"
2720
}

tests/webkit-playwright.js

Whitespace-only changes.

0 commit comments

Comments
 (0)