fix: await plugin.configure (#13834)

This commit is contained in:
Ross Wollman 2022-04-28 16:22:20 -07:00 committed by GitHub
parent f486ce8c06
commit 4984878411
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 25 additions and 12 deletions

View file

@ -150,7 +150,7 @@ async function runTests(args: string[], opts: { [key: string]: any }) {
return; return;
const runner = new Runner(overrides, { defaultConfig }); const runner = new Runner(overrides, { defaultConfig });
const config = resolvedConfigFile ? await runner.loadConfigFromResolvedFile(resolvedConfigFile) : runner.loadEmptyConfig(configFileOrDirectory); const config = resolvedConfigFile ? await runner.loadConfigFromResolvedFile(resolvedConfigFile) : await runner.loadEmptyConfig(configFileOrDirectory);
if (('projects' in config) && opts.browser) if (('projects' in config) && opts.browser)
throw new Error(`Cannot use --browser option when configuration file defines projects. Specify browserName in the projects instead.`); throw new Error(`Cannot use --browser option when configuration file defines projects. Specify browserName in the projects instead.`);

View file

@ -55,7 +55,7 @@ export class Loader {
if ('file' in data.configFile) if ('file' in data.configFile)
await loader.loadConfigFile(data.configFile.file); await loader.loadConfigFile(data.configFile.file);
else else
loader.loadEmptyConfig(data.configFile.configDir); await loader.loadEmptyConfig(data.configFile.configDir);
return loader; return loader;
} }
@ -67,23 +67,23 @@ export class Loader {
config = config['default']; config = config['default'];
this._configFile = file; this._configFile = file;
const rawConfig = { ...config }; const rawConfig = { ...config };
this._processConfigObject(config, path.dirname(file)); await this._processConfigObject(config, path.dirname(file));
return rawConfig; return rawConfig;
} }
loadEmptyConfig(configDir: string): Config { async loadEmptyConfig(configDir: string): Promise<Config> {
this._processConfigObject({}, configDir); await this._processConfigObject({}, configDir);
return {}; return {};
} }
private _processConfigObject(config: Config, configDir: string) { private async _processConfigObject(config: Config, configDir: string) {
if (config.webServer) { if (config.webServer) {
config.plugins = config.plugins || []; config.plugins = config.plugins || [];
config.plugins.push(_legacyWebServer(config.webServer)); config.plugins.push(_legacyWebServer(config.webServer));
} }
for (const plugin of config.plugins || []) for (const plugin of config.plugins || [])
plugin.configure?.(config, configDir); await plugin.configure?.(config, configDir);
this._configDir = configDir; this._configDir = configDir;
const packageJsonPath = getPackageJsonPath(configDir); const packageJsonPath = getPackageJsonPath(configDir);

View file

@ -69,7 +69,7 @@ export class Runner {
return await this._loader.loadConfigFile(resolvedConfigFile); return await this._loader.loadConfigFile(resolvedConfigFile);
} }
loadEmptyConfig(configFileOrDirectory: string): Config { loadEmptyConfig(configFileOrDirectory: string): Promise<Config> {
return this._loader.loadEmptyConfig(configFileOrDirectory); return this._loader.loadEmptyConfig(configFileOrDirectory);
} }

View file

@ -44,24 +44,37 @@ test('event order', async ({ runInlineTest }, testInfo) => {
`, `,
'globalSetup.ts': ` 'globalSetup.ts': `
import log from './log'; import log from './log';
const setup = () => log('globalSetup'); const setup = async () => {
await new Promise(r => setTimeout(r, 100));
log('globalSetup');
}
export default setup; export default setup;
`, `,
'globalTeardown.ts': ` 'globalTeardown.ts': `
import log from './log'; import log from './log';
const teardown = () => log('globalTeardown'); const teardown = async () => {
await new Promise(r => setTimeout(r, 100));
log('globalTeardown');
}
export default teardown; export default teardown;
`, `,
'plugin.ts': ` 'plugin.ts': `
import log from './log'; import log from './log';
export const myPlugin = (name: string) => ({ export const myPlugin = (name: string) => ({
configure: async (config) => { configure: async (config) => {
await new Promise(r => setTimeout(r, 100));
log(name, 'configure'); log(name, 'configure');
config.use = (config.use || {}); config.use = (config.use || {});
config.use.baseURL = (config.use.baseURL || '') + name + ' | '; config.use.baseURL = (config.use.baseURL || '') + name + ' | ';
}, },
setup: async () => log(name, 'setup'), setup: async () => {
teardown: async () => log(name, 'teardown'), await new Promise(r => setTimeout(r, 100));
log(name, 'setup');
},
teardown: async () => {
await new Promise(r => setTimeout(r, 100));
log(name, 'teardown');
},
}); });
`, `,
}); });