Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Jun 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/test/loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ export class Loader {
if (config && typeof config === 'object' && ('default' in config))
config = config['default'];
this._config = config;
this._configFile = file;
const rawConfig = { ...config };
this._processConfigObject(path.dirname(file));
this._configFile = file;
return rawConfig;
} catch (e) {
prependErrorMessage(e, `Error while reading ${file}:\n`);
Expand All @@ -77,6 +77,12 @@ export class Loader {
private _processConfigObject(rootDir: string) {
validateConfig(this._config);

// Resolve script hooks relative to the root dir.
if (this._config.globalSetup)
this._config.globalSetup = path.resolve(rootDir, this._config.globalSetup);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this should be resolved to the config file dir not to the root dir.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Root dir is the file dir (in this method :))

if (this._config.globalTeardown)
this._config.globalTeardown = path.resolve(rootDir, this._config.globalTeardown);

const configUse = mergeObjects(this._defaultConfig.use, this._config.use);
this._config = mergeObjects(mergeObjects(this._defaultConfig, this._config), { use: configUse });

Expand Down
18 changes: 9 additions & 9 deletions tests/playwright-test/global-setup.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ test('globalSetup and globalTeardown should work', async ({ runInlineTest }) =>
'playwright.config.ts': `
import * as path from 'path';
module.exports = {
globalSetup: path.join(__dirname, 'globalSetup.ts'),
globalSetup: 'globalSetup.ts',
globalTeardown: path.join(__dirname, 'globalTeardown.ts'),
};
`,
Expand Down Expand Up @@ -53,8 +53,8 @@ test('globalTeardown runs after failures', async ({ runInlineTest }) => {
'playwright.config.ts': `
import * as path from 'path';
module.exports = {
globalSetup: path.join(__dirname, 'globalSetup.ts'),
globalTeardown: path.join(__dirname, 'globalTeardown.ts'),
globalSetup: 'globalSetup.ts',
globalTeardown: 'globalTeardown.ts',
};
`,
'globalSetup.ts': `
Expand Down Expand Up @@ -85,8 +85,8 @@ test('globalTeardown does not run when globalSetup times out', async ({ runInlin
'playwright.config.ts': `
import * as path from 'path';
module.exports = {
globalSetup: path.join(__dirname, 'globalSetup.ts'),
globalTeardown: path.join(__dirname, 'globalTeardown.ts'),
globalSetup: 'globalSetup.ts',
globalTeardown: 'globalTeardown.ts',
globalTimeout: 1000,
};
`,
Expand Down Expand Up @@ -119,7 +119,7 @@ test('globalSetup should be run before requiring tests', async ({ runInlineTest
'playwright.config.ts': `
import * as path from 'path';
module.exports = {
globalSetup: path.join(__dirname, 'globalSetup.ts'),
globalSetup: 'globalSetup.ts',
};
`,
'globalSetup.ts': `
Expand All @@ -143,7 +143,7 @@ test('globalSetup should work with sync function', async ({ runInlineTest }) =>
'playwright.config.ts': `
import * as path from 'path';
module.exports = {
globalSetup: path.join(__dirname, 'globalSetup.ts'),
globalSetup: 'globalSetup.ts',
};
`,
'globalSetup.ts': `
Expand All @@ -167,7 +167,7 @@ test('globalSetup should throw when passed non-function', async ({ runInlineTest
'playwright.config.ts': `
import * as path from 'path';
module.exports = {
globalSetup: path.join(__dirname, 'globalSetup.ts'),
globalSetup: 'globalSetup.ts',
};
`,
'globalSetup.ts': `
Expand All @@ -187,7 +187,7 @@ test('globalSetup should work with default export and run the returned fn', asyn
'playwright.config.ts': `
import * as path from 'path';
module.exports = {
globalSetup: path.join(__dirname, 'globalSetup.ts'),
globalSetup: 'globalSetup.ts',
};
`,
'globalSetup.ts': `
Expand Down