From 57b5133d9af6b6cd30243748bb551b05ee8af7fd Mon Sep 17 00:00:00 2001 From: neverland Date: Wed, 1 Jan 2025 15:39:58 +0800 Subject: [PATCH 1/2] test(e2e): split slow test file --- e2e/cases/create-rsbuild/basic.test.ts | 22 +++ e2e/cases/create-rsbuild/helper.ts | 31 +++- e2e/cases/create-rsbuild/index.test.ts | 158 ------------------ e2e/cases/create-rsbuild/js-templates.test.ts | 45 +++++ e2e/cases/create-rsbuild/tools.test.ts | 70 ++++++++ e2e/cases/create-rsbuild/ts-templates.test.ts | 45 +++++ 6 files changed, 204 insertions(+), 167 deletions(-) create mode 100644 e2e/cases/create-rsbuild/basic.test.ts delete mode 100644 e2e/cases/create-rsbuild/index.test.ts create mode 100644 e2e/cases/create-rsbuild/js-templates.test.ts create mode 100644 e2e/cases/create-rsbuild/tools.test.ts create mode 100644 e2e/cases/create-rsbuild/ts-templates.test.ts diff --git a/e2e/cases/create-rsbuild/basic.test.ts b/e2e/cases/create-rsbuild/basic.test.ts new file mode 100644 index 0000000000..782388db1e --- /dev/null +++ b/e2e/cases/create-rsbuild/basic.test.ts @@ -0,0 +1,22 @@ +import { rspackOnlyTest } from '@e2e/helper'; +import { createAndValidate } from './helper'; + +rspackOnlyTest('should create vanilla project as expected', async () => { + await createAndValidate(__dirname, 'vanilla'); +}); + +rspackOnlyTest('should create vanilla-ts project as expected', async () => { + await createAndValidate(__dirname, 'vanilla-ts'); +}); + +rspackOnlyTest('should allow to create project in sub dir', async () => { + await createAndValidate(__dirname, 'vanilla', { + name: 'test-temp-dir/rsbuild-project', + }); +}); + +rspackOnlyTest('should allow to create project in relative dir', async () => { + await createAndValidate(__dirname, 'vanilla', { + name: './test-temp-relative-dir', + }); +}); diff --git a/e2e/cases/create-rsbuild/helper.ts b/e2e/cases/create-rsbuild/helper.ts index 276de74c7b..4c4d2c75bc 100644 --- a/e2e/cases/create-rsbuild/helper.ts +++ b/e2e/cases/create-rsbuild/helper.ts @@ -1,5 +1,5 @@ -import { execSync } from 'node:child_process'; -import { existsSync } from 'node:fs'; +import { exec } from 'node:child_process'; +import { access } from 'node:fs/promises'; import path from 'node:path'; import { expect } from '@playwright/test'; import fse from 'fs-extra'; @@ -14,7 +14,7 @@ export const expectPackageJson = ( expect(pkgJson.devDependencies['@rsbuild/core']).toBeTruthy(); }; -export const createAndValidate = ( +export const createAndValidate = async ( cwd: string, template: string, { @@ -28,7 +28,7 @@ export const createAndValidate = ( } = {}, ) => { const dir = path.join(cwd, name); - fse.removeSync(dir); + await fse.remove(dir); let command = `npx create-rsbuild -d ${name} -t ${template}`; if (tools.length) { @@ -36,19 +36,32 @@ export const createAndValidate = ( command += ` ${toolsCmd}`; } - execSync(command, { cwd }); + await new Promise((resolve, reject) => { + exec(command, { cwd }, (error) => { + if (error) { + reject(error); + } else { + resolve(); + } + }); + }); - const pkgJson = fse.readJSONSync(path.join(dir, 'package.json')); + const pkgJson = await fse.readJSON(path.join(dir, 'package.json')); expectPackageJson(pkgJson, path.basename(name)); if (template.endsWith('-ts')) { expect(pkgJson.devDependencies.typescript).toBeTruthy(); - expect(existsSync(path.join(dir, 'tsconfig.json'))).toBeTruthy(); + try { + await access(path.join(dir, 'tsconfig.json')); + expect(true).toBeTruthy(); + } catch { + expect(false).toBeTruthy(); + } } - const cleanFn = () => fse.removeSync(dir); + const cleanFn = async () => await fse.remove(dir); if (clean) { - cleanFn(); + await cleanFn(); } return { dir, pkgJson, clean: cleanFn }; diff --git a/e2e/cases/create-rsbuild/index.test.ts b/e2e/cases/create-rsbuild/index.test.ts deleted file mode 100644 index 2d5edb769e..0000000000 --- a/e2e/cases/create-rsbuild/index.test.ts +++ /dev/null @@ -1,158 +0,0 @@ -import { existsSync } from 'node:fs'; -import { join } from 'node:path'; -import { rspackOnlyTest } from '@e2e/helper'; -import { expect } from '@playwright/test'; -import { createAndValidate } from './helper'; - -rspackOnlyTest('should create vanilla project as expected', async () => { - createAndValidate(__dirname, 'vanilla'); -}); - -rspackOnlyTest('should create vanilla-ts project as expected', async () => { - createAndValidate(__dirname, 'vanilla-ts'); -}); - -rspackOnlyTest('should create react project as expected', async () => { - const { pkgJson } = createAndValidate(__dirname, 'react'); - expect(pkgJson.dependencies.react).toBeTruthy(); - expect(pkgJson.dependencies['react-dom']).toBeTruthy(); - expect(pkgJson.devDependencies['@rsbuild/plugin-react']).toBeTruthy(); -}); - -rspackOnlyTest('should create react-ts project as expected', async () => { - const { pkgJson } = createAndValidate(__dirname, 'react-ts'); - expect(pkgJson.dependencies.react).toBeTruthy(); - expect(pkgJson.dependencies['react-dom']).toBeTruthy(); - expect(pkgJson.devDependencies['@rsbuild/plugin-react']).toBeTruthy(); -}); - -rspackOnlyTest('should create preact project as expected', async () => { - const { pkgJson } = createAndValidate(__dirname, 'preact'); - expect(pkgJson.dependencies.preact).toBeTruthy(); - expect(pkgJson.devDependencies['@rsbuild/plugin-preact']).toBeTruthy(); -}); - -rspackOnlyTest('should create preact-ts project as expected', async () => { - const { pkgJson } = createAndValidate(__dirname, 'preact-ts'); - expect(pkgJson.dependencies.preact).toBeTruthy(); - expect(pkgJson.devDependencies['@rsbuild/plugin-preact']).toBeTruthy(); -}); - -rspackOnlyTest('should create vue3 project as expected', async () => { - const { pkgJson } = createAndValidate(__dirname, 'vue3'); - expect(pkgJson.dependencies.vue).toBeTruthy(); - expect(pkgJson.devDependencies['@rsbuild/plugin-vue']).toBeTruthy(); -}); - -rspackOnlyTest('should create vue3-ts project as expected', async () => { - const { pkgJson } = createAndValidate(__dirname, 'vue3-ts'); - expect(pkgJson.dependencies.vue).toBeTruthy(); - expect(pkgJson.devDependencies['@rsbuild/plugin-vue']).toBeTruthy(); -}); - -rspackOnlyTest('should create vue2 project as expected', async () => { - const { pkgJson } = createAndValidate(__dirname, 'vue2'); - expect(pkgJson.dependencies.vue).toBeTruthy(); - expect(pkgJson.devDependencies['@rsbuild/plugin-vue2']).toBeTruthy(); -}); - -rspackOnlyTest('should create vue2-ts project as expected', async () => { - const { pkgJson } = createAndValidate(__dirname, 'vue2-ts'); - expect(pkgJson.dependencies.vue).toBeTruthy(); - expect(pkgJson.devDependencies['@rsbuild/plugin-vue2']).toBeTruthy(); -}); - -rspackOnlyTest('should create lit project as expected', async () => { - const { pkgJson } = createAndValidate(__dirname, 'lit'); - expect(pkgJson.dependencies.lit).toBeTruthy(); -}); - -rspackOnlyTest('should create lit-ts project as expected', async () => { - const { pkgJson } = createAndValidate(__dirname, 'lit-ts'); - expect(pkgJson.dependencies.lit).toBeTruthy(); -}); - -rspackOnlyTest('should create solid project as expected', async () => { - const { pkgJson } = createAndValidate(__dirname, 'solid'); - expect(pkgJson.dependencies['solid-js']).toBeTruthy(); - expect(pkgJson.devDependencies['@rsbuild/plugin-solid']).toBeTruthy(); -}); - -rspackOnlyTest('should create solid-ts project as expected', async () => { - const { pkgJson } = createAndValidate(__dirname, 'solid-ts'); - expect(pkgJson.dependencies['solid-js']).toBeTruthy(); - expect(pkgJson.devDependencies['@rsbuild/plugin-solid']).toBeTruthy(); -}); - -rspackOnlyTest('should create svelte project as expected', async () => { - const { pkgJson } = createAndValidate(__dirname, 'svelte'); - expect(pkgJson.dependencies.svelte).toBeTruthy(); - expect(pkgJson.devDependencies['@rsbuild/plugin-svelte']).toBeTruthy(); -}); - -rspackOnlyTest('should create svelte-ts project as expected', async () => { - const { pkgJson } = createAndValidate(__dirname, 'svelte-ts'); - expect(pkgJson.dependencies.svelte).toBeTruthy(); - expect(pkgJson.devDependencies['@rsbuild/plugin-svelte']).toBeTruthy(); -}); - -rspackOnlyTest('should allow to create project in sub dir', async () => { - createAndValidate(__dirname, 'vanilla', { - name: 'test-temp-dir/rsbuild-project', - }); -}); - -rspackOnlyTest('should allow to create project in relative dir', async () => { - createAndValidate(__dirname, 'vanilla', { - name: './test-temp-relative-dir', - }); -}); - -rspackOnlyTest('should create project with eslint as expected', async () => { - const { dir, pkgJson, clean } = createAndValidate(__dirname, 'vanilla', { - name: 'test-temp-eslint', - tools: ['eslint'], - clean: false, - }); - expect(pkgJson.devDependencies.eslint).toBeTruthy(); - expect(existsSync(join(dir, 'eslint.config.mjs'))).toBeTruthy(); - clean(); -}); - -rspackOnlyTest('should create project with prettier as expected', async () => { - const { dir, pkgJson, clean } = createAndValidate(__dirname, 'vanilla', { - name: 'test-temp-prettier', - tools: ['prettier'], - clean: false, - }); - expect(pkgJson.devDependencies.prettier).toBeTruthy(); - expect(existsSync(join(dir, '.prettierrc'))).toBeTruthy(); - clean(); -}); - -rspackOnlyTest( - 'should create project with eslint and prettier as expected', - async () => { - const { dir, pkgJson, clean } = createAndValidate(__dirname, 'vanilla', { - name: 'test-temp-eslint-prettier', - tools: ['eslint', 'prettier'], - clean: false, - }); - expect(pkgJson.devDependencies.eslint).toBeTruthy(); - expect(pkgJson.devDependencies.prettier).toBeTruthy(); - expect(existsSync(join(dir, '.prettierrc'))).toBeTruthy(); - expect(existsSync(join(dir, 'eslint.config.mjs'))).toBeTruthy(); - clean(); - }, -); - -rspackOnlyTest('should create project with biome as expected', async () => { - const { dir, pkgJson, clean } = createAndValidate(__dirname, 'vanilla', { - name: 'test-temp-eslint', - tools: ['biome'], - clean: false, - }); - expect(pkgJson.devDependencies['@biomejs/biome']).toBeTruthy(); - expect(existsSync(join(dir, 'biome.json'))).toBeTruthy(); - clean(); -}); diff --git a/e2e/cases/create-rsbuild/js-templates.test.ts b/e2e/cases/create-rsbuild/js-templates.test.ts new file mode 100644 index 0000000000..3cc9dfbf77 --- /dev/null +++ b/e2e/cases/create-rsbuild/js-templates.test.ts @@ -0,0 +1,45 @@ +import { rspackOnlyTest } from '@e2e/helper'; +import { expect } from '@playwright/test'; +import { createAndValidate } from './helper'; + +rspackOnlyTest('should create react project as expected', async () => { + const { pkgJson } = await createAndValidate(__dirname, 'react'); + expect(pkgJson.dependencies.react).toBeTruthy(); + expect(pkgJson.dependencies['react-dom']).toBeTruthy(); + expect(pkgJson.devDependencies['@rsbuild/plugin-react']).toBeTruthy(); +}); + +rspackOnlyTest('should create preact project as expected', async () => { + const { pkgJson } = await createAndValidate(__dirname, 'preact'); + expect(pkgJson.dependencies.preact).toBeTruthy(); + expect(pkgJson.devDependencies['@rsbuild/plugin-preact']).toBeTruthy(); +}); + +rspackOnlyTest('should create vue3 project as expected', async () => { + const { pkgJson } = await createAndValidate(__dirname, 'vue3'); + expect(pkgJson.dependencies.vue).toBeTruthy(); + expect(pkgJson.devDependencies['@rsbuild/plugin-vue']).toBeTruthy(); +}); + +rspackOnlyTest('should create vue2 project as expected', async () => { + const { pkgJson } = await createAndValidate(__dirname, 'vue2'); + expect(pkgJson.dependencies.vue).toBeTruthy(); + expect(pkgJson.devDependencies['@rsbuild/plugin-vue2']).toBeTruthy(); +}); + +rspackOnlyTest('should create lit project as expected', async () => { + const { pkgJson } = await createAndValidate(__dirname, 'lit'); + expect(pkgJson.dependencies.lit).toBeTruthy(); +}); + +rspackOnlyTest('should create solid project as expected', async () => { + const { pkgJson } = await createAndValidate(__dirname, 'solid'); + expect(pkgJson.dependencies['solid-js']).toBeTruthy(); + expect(pkgJson.devDependencies['@rsbuild/plugin-solid']).toBeTruthy(); +}); + +rspackOnlyTest('should create svelte project as expected', async () => { + const { pkgJson } = await createAndValidate(__dirname, 'svelte'); + expect(pkgJson.dependencies.svelte).toBeTruthy(); + expect(pkgJson.devDependencies['@rsbuild/plugin-svelte']).toBeTruthy(); +}); diff --git a/e2e/cases/create-rsbuild/tools.test.ts b/e2e/cases/create-rsbuild/tools.test.ts new file mode 100644 index 0000000000..50c954b9ec --- /dev/null +++ b/e2e/cases/create-rsbuild/tools.test.ts @@ -0,0 +1,70 @@ +import { existsSync } from 'node:fs'; +import { join } from 'node:path'; +import { rspackOnlyTest } from '@e2e/helper'; +import { expect } from '@playwright/test'; +import { createAndValidate } from './helper'; + +rspackOnlyTest('should create project with eslint as expected', async () => { + const { dir, pkgJson, clean } = await createAndValidate( + __dirname, + 'vanilla', + { + name: 'test-temp-eslint', + tools: ['eslint'], + clean: false, + }, + ); + expect(pkgJson.devDependencies.eslint).toBeTruthy(); + expect(existsSync(join(dir, 'eslint.config.mjs'))).toBeTruthy(); + await clean(); +}); + +rspackOnlyTest('should create project with prettier as expected', async () => { + const { dir, pkgJson, clean } = await createAndValidate( + __dirname, + 'vanilla', + { + name: 'test-temp-prettier', + tools: ['prettier'], + clean: false, + }, + ); + expect(pkgJson.devDependencies.prettier).toBeTruthy(); + expect(existsSync(join(dir, '.prettierrc'))).toBeTruthy(); + await clean(); +}); + +rspackOnlyTest( + 'should create project with eslint and prettier as expected', + async () => { + const { dir, pkgJson, clean } = await createAndValidate( + __dirname, + 'vanilla', + { + name: 'test-temp-eslint-prettier', + tools: ['eslint', 'prettier'], + clean: false, + }, + ); + expect(pkgJson.devDependencies.eslint).toBeTruthy(); + expect(pkgJson.devDependencies.prettier).toBeTruthy(); + expect(existsSync(join(dir, '.prettierrc'))).toBeTruthy(); + expect(existsSync(join(dir, 'eslint.config.mjs'))).toBeTruthy(); + await clean(); + }, +); + +rspackOnlyTest('should create project with biome as expected', async () => { + const { dir, pkgJson, clean } = await createAndValidate( + __dirname, + 'vanilla', + { + name: 'test-temp-eslint', + tools: ['biome'], + clean: false, + }, + ); + expect(pkgJson.devDependencies['@biomejs/biome']).toBeTruthy(); + expect(existsSync(join(dir, 'biome.json'))).toBeTruthy(); + await clean(); +}); diff --git a/e2e/cases/create-rsbuild/ts-templates.test.ts b/e2e/cases/create-rsbuild/ts-templates.test.ts new file mode 100644 index 0000000000..4ca32dbc3d --- /dev/null +++ b/e2e/cases/create-rsbuild/ts-templates.test.ts @@ -0,0 +1,45 @@ +import { rspackOnlyTest } from '@e2e/helper'; +import { expect } from '@playwright/test'; +import { createAndValidate } from './helper'; + +rspackOnlyTest('should create react-ts project as expected', async () => { + const { pkgJson } = await createAndValidate(__dirname, 'react-ts'); + expect(pkgJson.dependencies.react).toBeTruthy(); + expect(pkgJson.dependencies['react-dom']).toBeTruthy(); + expect(pkgJson.devDependencies['@rsbuild/plugin-react']).toBeTruthy(); +}); + +rspackOnlyTest('should create preact-ts project as expected', async () => { + const { pkgJson } = await createAndValidate(__dirname, 'preact-ts'); + expect(pkgJson.dependencies.preact).toBeTruthy(); + expect(pkgJson.devDependencies['@rsbuild/plugin-preact']).toBeTruthy(); +}); + +rspackOnlyTest('should create vue3-ts project as expected', async () => { + const { pkgJson } = await createAndValidate(__dirname, 'vue3-ts'); + expect(pkgJson.dependencies.vue).toBeTruthy(); + expect(pkgJson.devDependencies['@rsbuild/plugin-vue']).toBeTruthy(); +}); + +rspackOnlyTest('should create vue2-ts project as expected', async () => { + const { pkgJson } = await createAndValidate(__dirname, 'vue2-ts'); + expect(pkgJson.dependencies.vue).toBeTruthy(); + expect(pkgJson.devDependencies['@rsbuild/plugin-vue2']).toBeTruthy(); +}); + +rspackOnlyTest('should create lit-ts project as expected', async () => { + const { pkgJson } = await createAndValidate(__dirname, 'lit-ts'); + expect(pkgJson.dependencies.lit).toBeTruthy(); +}); + +rspackOnlyTest('should create solid-ts project as expected', async () => { + const { pkgJson } = await createAndValidate(__dirname, 'solid-ts'); + expect(pkgJson.dependencies['solid-js']).toBeTruthy(); + expect(pkgJson.devDependencies['@rsbuild/plugin-solid']).toBeTruthy(); +}); + +rspackOnlyTest('should create svelte-ts project as expected', async () => { + const { pkgJson } = await createAndValidate(__dirname, 'svelte-ts'); + expect(pkgJson.dependencies.svelte).toBeTruthy(); + expect(pkgJson.devDependencies['@rsbuild/plugin-svelte']).toBeTruthy(); +}); From e30caba86afbf8a6f1d33c96ffb5a91f85c2a06a Mon Sep 17 00:00:00 2001 From: neverland Date: Wed, 1 Jan 2025 15:42:16 +0800 Subject: [PATCH 2/2] fix: lint --- .../create-rsbuild/{js-templates.test.ts => jsTemplates.test.ts} | 0 .../create-rsbuild/{ts-templates.test.ts => tsTemplates.test.ts} | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename e2e/cases/create-rsbuild/{js-templates.test.ts => jsTemplates.test.ts} (100%) rename e2e/cases/create-rsbuild/{ts-templates.test.ts => tsTemplates.test.ts} (100%) diff --git a/e2e/cases/create-rsbuild/js-templates.test.ts b/e2e/cases/create-rsbuild/jsTemplates.test.ts similarity index 100% rename from e2e/cases/create-rsbuild/js-templates.test.ts rename to e2e/cases/create-rsbuild/jsTemplates.test.ts diff --git a/e2e/cases/create-rsbuild/ts-templates.test.ts b/e2e/cases/create-rsbuild/tsTemplates.test.ts similarity index 100% rename from e2e/cases/create-rsbuild/ts-templates.test.ts rename to e2e/cases/create-rsbuild/tsTemplates.test.ts