Skip to content

Commit 5c35cfe

Browse files
authored
[DEVX-1190] merge configs (#116)
* Merge config needed to run in sauce with customer's config * fix unit test * use correct key for headless
1 parent da9a359 commit 5c35cfe

File tree

8 files changed

+77
-8
lines changed

8 files changed

+77
-8
lines changed

src/playwright-runner.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,8 +238,8 @@ async function run (nodeBin, runCfgPath, suiteName) {
238238

239239
// Copy our runner's playwright config to a custom location in order to
240240
// preserve the customer's config which we may want to load in the future
241-
const configFile = path.join(projectPath, 'custom.config.js');
242-
fs.copyFileSync(path.join(__dirname, 'playwright.config.js'), configFile);
241+
const configFile = path.join(projectPath, 'sauce.config.js');
242+
fs.copyFileSync(path.join(__dirname, 'sauce.config.js'), configFile);
243243

244244
const defaultArgs = {
245245
output: assetsDir,

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

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
const process = require('process');
2+
const _ = require('lodash');
23

3-
const defaults = {
4+
let userConfig = {};
5+
try {
6+
userConfig = require('./playwright.config.js');
7+
} catch {}
8+
9+
const overrides = {
410
use: {
5-
headed: process.env.SAUCE_VM ? true : false,
11+
headless: process.env.SAUCE_VM ? false : true,
612
video: process.env.SAUCE_VM ? 'off' : 'on',
713
},
814
reporter: [
@@ -18,9 +24,9 @@ if ('HTTP_PROXY' in process.env && process.env.HTTP_PROXY !== '') {
1824
server: process.env.HTTP_PROXY,
1925
};
2026

21-
defaults.use.contextOptions = { proxy, ignoreHTTPSErrors: true };
27+
overrides.use.contextOptions = { proxy, ignoreHTTPSErrors: true };
2228
// Need to set the browser launch option as well, it is a hard requirement when testing chromium + windows.
23-
defaults.use.launchOptions = { proxy, ignoreHTTPSErrors: true };
29+
overrides.use.launchOptions = { proxy, ignoreHTTPSErrors: true };
2430
}
2531

26-
module.exports = defaults;
32+
module.exports = _.merge(userConfig, overrides);
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
sauce.config.js
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Config Merging Playwright Test
2+
3+
Small test to ensure local playwright config is being preserved.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/** @type {import('@playwright/test').PlaywrightTestConfig} */
2+
module.exports = {
3+
use: {
4+
'headed': false,
5+
'video': false,
6+
'timezoneId': 'Asia/Seoul',
7+
reporter: [['dot']],
8+
},
9+
};
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"sauce": {
3+
"region": "us-west-1",
4+
"metadata": {
5+
"tags": ["tag1", "tag2"],
6+
"build": "Local Test Build"
7+
}
8+
},
9+
"playwright": {
10+
"version": "1.12.3",
11+
"projectPath": "./tests/fixtures/basic-js/"
12+
},
13+
"suites": [
14+
{
15+
"name": "config-merging",
16+
"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
25+
},
26+
"testMatch": ".*.js"
27+
}
28+
]
29+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/**
2+
* Copyright Microsoft Corporation. All rights reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
const { test, expect } = require('@playwright/test');
17+
18+
test('timezone is being set from config', async ({ page }) => {
19+
await page.goto('https://whatismytimezone.com/');
20+
await expect(page.locator('article').first()).toContainText('Korean Standard Time');
21+
});

tests/unit/src/playwright-runner.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ describe('playwright-runner', function () {
8080
'--output',
8181
path.join(MOCK_CWD, '__assets__'),
8282
'--config',
83-
path.join(MOCK_CWD, 'custom.config.js'),
83+
path.join(MOCK_CWD, 'sauce.config.js'),
8484
'--browser',
8585
'chromium',
8686
'--headed',

0 commit comments

Comments
 (0)