-
Notifications
You must be signed in to change notification settings - Fork 68
fix(ct): run vite server once on init #1166
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,7 +13,9 @@ import { plugin as generateIndexHtml } from "./plugins/generate-index-html"; | |
| import { plugin as mockPlugin } from "./plugins/mock"; | ||
| import { ManualMock } from "./manual-mock"; | ||
| import { Config } from "../../../config"; | ||
| import RuntimeConfig from "../../../config/runtime-config"; | ||
| import { VITE_DEFAULT_CONFIG_ENV } from "./constants"; | ||
| import defaults from "../../../config/defaults"; | ||
|
|
||
| import type { ViteDevServer, UserConfig, InlineConfig } from "vite"; | ||
| import type { BrowserTestRunEnvOptions } from "./types"; | ||
|
|
@@ -76,6 +78,8 @@ export class ViteServer { | |
|
|
||
| await this._server.listen(); | ||
|
|
||
| this._useBaseUrlFromVite(); | ||
|
|
||
| logger.log(chalk.green(`Vite server started on ${this.baseUrl}`)); | ||
| } | ||
|
|
||
|
|
@@ -115,4 +119,21 @@ export class ViteServer { | |
| get baseUrl(): string | undefined { | ||
| return this._server?.resolvedUrls!.local[0]; | ||
| } | ||
|
|
||
| private _useBaseUrlFromVite(): void { | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. also moved from |
||
| const viteBaseUrl = this.baseUrl!; | ||
| const defaultBaseUrl = defaults.baseUrl; | ||
|
|
||
| RuntimeConfig.getInstance().extend({ viteBaseUrl }); | ||
|
|
||
| if (this._testplaneConfig.baseUrl === defaultBaseUrl) { | ||
| this._testplaneConfig.baseUrl = viteBaseUrl; | ||
| } | ||
|
|
||
| for (const broConfig of Object.values(this._testplaneConfig.browsers)) { | ||
| if (broConfig.baseUrl === defaultBaseUrl) { | ||
| broConfig.baseUrl = viteBaseUrl; | ||
| } | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,8 +3,7 @@ import _ from "lodash"; | |
| import fs from "fs-extra"; | ||
| import { Stats as RunnerStats } from "./stats"; | ||
| import { BaseTestplane } from "./base-testplane"; | ||
| import type { MainRunner as NodejsEnvRunner } from "./runner"; | ||
| import type { MainRunner as BrowserEnvRunner } from "./runner/browser-env"; | ||
| import type { MainRunner } from "./runner"; | ||
| import RuntimeConfig from "./config/runtime-config"; | ||
| import { MasterAsyncEvents, MasterEvents, MasterSyncEvents } from "./events"; | ||
| import eventsUtils from "./events/utils"; | ||
|
|
@@ -19,6 +18,7 @@ import { initDevServer } from "./dev-server"; | |
| import { ConfigInput } from "./config/types"; | ||
| import { MasterEventHandler, Test, TestResult } from "./types"; | ||
| import { preloadWebdriverIO } from "./utils/preload-utils"; | ||
| import { ViteServer } from "./runner/browser-env/vite/server"; | ||
|
|
||
| interface RunOpts { | ||
| browsers: string[]; | ||
|
|
@@ -70,14 +70,16 @@ export interface Testplane { | |
| export class Testplane extends BaseTestplane { | ||
| protected failed: boolean; | ||
| protected failedList: FailedListItem[]; | ||
| protected runner: NodejsEnvRunner | BrowserEnvRunner | null; | ||
| protected runner: MainRunner | null; | ||
| protected viteServer: ViteServer | null; | ||
|
|
||
| constructor(config?: string | ConfigInput) { | ||
| super(config); | ||
|
|
||
| this.failed = false; | ||
| this.failedList = []; | ||
| this.runner = null; | ||
| this.viteServer = null; | ||
| } | ||
|
|
||
| extendCli(parser: Command): void { | ||
|
|
@@ -91,6 +93,15 @@ export class Testplane extends BaseTestplane { | |
| configPath: this._config.configPath, | ||
| }); | ||
|
|
||
| if (!isRunInNodeJsEnv(this._config)) { | ||
| try { | ||
| this.viteServer = ViteServer.create(this._config); | ||
| await this.viteServer.start(); | ||
| } catch (err) { | ||
| throw new Error(`Vite server failed to start: ${(err as Error).message}`); | ||
| } | ||
| } | ||
|
|
||
| return super._init(); | ||
| } | ||
|
|
||
|
|
@@ -126,9 +137,7 @@ export class Testplane extends BaseTestplane { | |
| this._config.system.mochaOpts.timeout = 0; | ||
| } | ||
|
|
||
| const RunnerClass = isRunInNodeJsEnv(this._config) | ||
| ? await import("./runner").then(m => m.MainRunner) | ||
| : await import("./runner/browser-env").then(m => m.MainRunner); | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. browser-env runner is not needed anymore, I removed it |
||
| const RunnerClass = await import("./runner").then(m => m.MainRunner); | ||
|
|
||
| const runner = RunnerClass.create(this._config, this._interceptors); | ||
| this.runner = runner; | ||
|
|
@@ -257,6 +266,10 @@ export class Testplane extends BaseTestplane { | |
| }, timeout).unref(); | ||
| } | ||
|
|
||
| if (this.viteServer) { | ||
| this.viteServer.close(); | ||
| } | ||
|
|
||
| if (this.runner) { | ||
| this.runner.cancel(); | ||
| } | ||
|
|
||
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
moved here from
src/runner/browser-env/index.ts(which is not needed anymore)