fix(test-runner): resolve global hooks relative to the config dir (#7061)

This commit is contained in:
Pavel Feldman 2021-06-10 22:31:27 -07:00 committed by GitHub
parent cbce7cbdec
commit 49a8f67c0f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 10 deletions

View File

@ -57,9 +57,9 @@ export class Loader {
if (config && typeof config === 'object' && ('default' in config)) if (config && typeof config === 'object' && ('default' in config))
config = config['default']; config = config['default'];
this._config = config; this._config = config;
this._configFile = file;
const rawConfig = { ...config }; const rawConfig = { ...config };
this._processConfigObject(path.dirname(file)); this._processConfigObject(path.dirname(file));
this._configFile = file;
return rawConfig; return rawConfig;
} catch (e) { } catch (e) {
prependErrorMessage(e, `Error while reading ${file}:\n`); prependErrorMessage(e, `Error while reading ${file}:\n`);
@ -77,6 +77,12 @@ export class Loader {
private _processConfigObject(rootDir: string) { private _processConfigObject(rootDir: string) {
validateConfig(this._config); validateConfig(this._config);
// Resolve script hooks relative to the root dir.
if (this._config.globalSetup)
this._config.globalSetup = path.resolve(rootDir, this._config.globalSetup);
if (this._config.globalTeardown)
this._config.globalTeardown = path.resolve(rootDir, this._config.globalTeardown);
const configUse = mergeObjects(this._defaultConfig.use, this._config.use); const configUse = mergeObjects(this._defaultConfig.use, this._config.use);
this._config = mergeObjects(mergeObjects(this._defaultConfig, this._config), { use: configUse }); this._config = mergeObjects(mergeObjects(this._defaultConfig, this._config), { use: configUse });

View File

@ -21,7 +21,7 @@ test('globalSetup and globalTeardown should work', async ({ runInlineTest }) =>
'playwright.config.ts': ` 'playwright.config.ts': `
import * as path from 'path'; import * as path from 'path';
module.exports = { module.exports = {
globalSetup: path.join(__dirname, 'globalSetup.ts'), globalSetup: 'globalSetup.ts',
globalTeardown: path.join(__dirname, 'globalTeardown.ts'), globalTeardown: path.join(__dirname, 'globalTeardown.ts'),
}; };
`, `,
@ -53,8 +53,8 @@ test('globalTeardown runs after failures', async ({ runInlineTest }) => {
'playwright.config.ts': ` 'playwright.config.ts': `
import * as path from 'path'; import * as path from 'path';
module.exports = { module.exports = {
globalSetup: path.join(__dirname, 'globalSetup.ts'), globalSetup: 'globalSetup.ts',
globalTeardown: path.join(__dirname, 'globalTeardown.ts'), globalTeardown: 'globalTeardown.ts',
}; };
`, `,
'globalSetup.ts': ` 'globalSetup.ts': `
@ -85,8 +85,8 @@ test('globalTeardown does not run when globalSetup times out', async ({ runInlin
'playwright.config.ts': ` 'playwright.config.ts': `
import * as path from 'path'; import * as path from 'path';
module.exports = { module.exports = {
globalSetup: path.join(__dirname, 'globalSetup.ts'), globalSetup: 'globalSetup.ts',
globalTeardown: path.join(__dirname, 'globalTeardown.ts'), globalTeardown: 'globalTeardown.ts',
globalTimeout: 1000, globalTimeout: 1000,
}; };
`, `,
@ -119,7 +119,7 @@ test('globalSetup should be run before requiring tests', async ({ runInlineTest
'playwright.config.ts': ` 'playwright.config.ts': `
import * as path from 'path'; import * as path from 'path';
module.exports = { module.exports = {
globalSetup: path.join(__dirname, 'globalSetup.ts'), globalSetup: 'globalSetup.ts',
}; };
`, `,
'globalSetup.ts': ` 'globalSetup.ts': `
@ -143,7 +143,7 @@ test('globalSetup should work with sync function', async ({ runInlineTest }) =>
'playwright.config.ts': ` 'playwright.config.ts': `
import * as path from 'path'; import * as path from 'path';
module.exports = { module.exports = {
globalSetup: path.join(__dirname, 'globalSetup.ts'), globalSetup: 'globalSetup.ts',
}; };
`, `,
'globalSetup.ts': ` 'globalSetup.ts': `
@ -167,7 +167,7 @@ test('globalSetup should throw when passed non-function', async ({ runInlineTest
'playwright.config.ts': ` 'playwright.config.ts': `
import * as path from 'path'; import * as path from 'path';
module.exports = { module.exports = {
globalSetup: path.join(__dirname, 'globalSetup.ts'), globalSetup: 'globalSetup.ts',
}; };
`, `,
'globalSetup.ts': ` 'globalSetup.ts': `
@ -187,7 +187,7 @@ test('globalSetup should work with default export and run the returned fn', asyn
'playwright.config.ts': ` 'playwright.config.ts': `
import * as path from 'path'; import * as path from 'path';
module.exports = { module.exports = {
globalSetup: path.join(__dirname, 'globalSetup.ts'), globalSetup: 'globalSetup.ts',
}; };
`, `,
'globalSetup.ts': ` 'globalSetup.ts': `