ci: start devServer before test running to avoid tests timeout (#11297)

This commit is contained in:
Brooooooklyn
2025-03-31 10:39:34 +00:00
parent eda680ccdc
commit 47a8d15878
10 changed files with 117 additions and 73 deletions
+35
View File
@@ -0,0 +1,35 @@
import { getConfig, start } from '@affine-tools/cli/bundle';
import { Workspace } from '@affine-tools/utils/workspace';
import webpack from 'webpack';
export default async () => {
const ws = new Workspace();
const webpackConfig = await getConfig(ws.getPackage('@affine/web'), true);
const definedPort = webpackConfig.devServer?.port ?? 8080;
await new Promise<void>((resolve, reject) => {
start(webpack(webpackConfig), {
...webpackConfig.devServer,
onListening: server => {
// dev server has already started
if (server.options.port !== definedPort) {
server.compiler.close(reject);
server.stop().catch(reject);
resolve();
}
},
proxy: [],
})
.then(server => {
server.middleware?.waitUntilValid?.(stats => {
if (stats?.hasErrors()) {
reject(new Error('Webpack build failed'));
} else {
resolve();
}
});
})
.catch(reject);
});
console.log('Dev server started');
};
+4 -1
View File
@@ -7,7 +7,10 @@
},
"devDependencies": {
"@affine-test/kit": "workspace:*",
"@playwright/test": "=1.51.1"
"@affine-tools/cli": "workspace:*",
"@affine-tools/utils": "workspace:*",
"@playwright/test": "=1.51.1",
"webpack": "^5.98.0"
},
"version": "0.20.0"
}
+1 -14
View File
@@ -3,7 +3,6 @@ import type {
PlaywrightTestConfig,
PlaywrightWorkerOptions,
} from '@playwright/test';
// import { devices } from '@playwright/test';
/**
* Read environment variables from file.
@@ -19,6 +18,7 @@ const config: PlaywrightTestConfig = {
fullyParallel: true,
timeout: process.env.CI ? 50_000 : 30_000,
outputDir: testResultDir,
globalSetup: './dev-server.ts',
use: {
baseURL: 'http://localhost:8080/',
browserName:
@@ -42,19 +42,6 @@ const config: PlaywrightTestConfig = {
// default 'list' when running locally
// See https://playwright.dev/docs/test-reporters#github-actions-annotations
reporter: process.env.CI ? 'github' : 'list',
webServer: [
// Intentionally not building the web, reminds you to run it by yourself.
{
command: 'yarn run -T affine dev -p @affine/web',
port: 8080,
timeout: 120 * 1000,
reuseExistingServer: !process.env.CI,
env: {
COVERAGE: process.env.COVERAGE || 'false',
},
},
],
};
if (process.env.CI) {
+5 -1
View File
@@ -6,5 +6,9 @@
"tsBuildInfoFile": "./dist/tsconfig.tsbuildinfo"
},
"include": ["./e2e"],
"references": [{ "path": "../kit" }]
"references": [
{ "path": "../kit" },
{ "path": "../../tools/cli" },
{ "path": "../../tools/utils" }
]
}