Skip to content

Commit

Permalink
ci: run tests sequentially (#5677)
Browse files Browse the repository at this point in the history
  • Loading branch information
sheremet-va committed May 8, 2024
1 parent bcccce6 commit f2e15f7
Show file tree
Hide file tree
Showing 9 changed files with 83 additions and 37 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest]
node_version: [18, 20, 22]
node_version: [18, 20]
# node_version: [18, 20, 22] 22 when LTS is close enough
include:
- os: macos-14
node_version: 20
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"publish-ci": "tsx scripts/publish-ci.ts",
"release": "bumpp package.json packages/*/package.json --commit --push --tag && git update-ref refs/heads/release refs/heads/main && git push origin release",
"test": "pnpm --filter test-core test:threads",
"test:ci": "CI=true pnpm -r --reporter-hide-prefix --stream --filter '@vitest/test-*' --filter !test-browser run test",
"test:ci": "CI=true pnpm -r --reporter-hide-prefix --stream --sequential --filter '@vitest/test-*' --filter !test-browser run test",
"test:examples": "CI=true pnpm -r --reporter-hide-prefix --stream --filter '@vitest/example-*' run test",
"test:ecosystem-ci": "ECOSYSTEM_CI=true pnpm test:ci",
"typecheck": "tsc -p tsconfig.check.json --noEmit",
Expand Down Expand Up @@ -70,6 +70,7 @@
},
"pnpm": {
"overrides": {
"mlly": "^1.7.0",
"rollup": "$rollup",
"vite": "$vite",
"vitest": "workspace:*"
Expand Down
11 changes: 5 additions & 6 deletions packages/vitest/src/runtime/external-executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export class ExternalModulesExecutor {
// dynamic import can be used in both ESM and CJS, so we have it in the executor
public importModuleDynamically = async (specifier: string, referencer: VMModule) => {
const module = await this.resolveModule(specifier, referencer.identifier)
return this.esm.evaluateModule(module)
return await this.esm.evaluateModule(module)
}

public resolveModule = async (specifier: string, referencer: string) => {
Expand Down Expand Up @@ -220,7 +220,7 @@ export class ExternalModulesExecutor {

switch (type) {
case 'data':
return this.esm.createDataModule(identifier)
return await this.esm.createDataModule(identifier)
case 'builtin': {
const exports = this.require(identifier)
return this.wrapCoreSynteticModule(identifier, exports)
Expand All @@ -230,14 +230,13 @@ export class ExternalModulesExecutor {
case 'wasm':
return await this.esm.createWebAssemblyModule(url, () => this.fs.readBuffer(path))
case 'module':
return await this.esm.createEsModule(url, () => this.fs.readFile(path))
return await this.esm.createEsModule(url, () => this.fs.readFileAsync(path))
case 'commonjs': {
const exports = this.require(path)
return this.wrapCommonJsSynteticModule(identifier, exports)
}
case 'network': {
return this.esm.createNetworkModule(url)
}
case 'network':
return await this.esm.createNetworkModule(url)
default: {
const _deadend: never = type
return _deadend
Expand Down
18 changes: 12 additions & 6 deletions packages/vitest/src/runtime/vm/esm-executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,27 +40,33 @@ export class EsmExecutor {
return m
}

public async createEsModule(fileUrl: string, getCode: () => Promise<string> | string) {
const cached = this.moduleCache.get(fileUrl)
public async createEsModule(fileURL: string, getCode: () => Promise<string> | string) {
const cached = this.moduleCache.get(fileURL)
if (cached)
return cached
const promise = this.loadEsModule(fileURL, getCode)
this.moduleCache.set(fileURL, promise)
return promise
}

private async loadEsModule(fileURL: string, getCode: () => string | Promise<string>) {
const code = await getCode()
// TODO: should not be allowed in strict mode, implement in #2854
if (fileUrl.endsWith('.json')) {
if (fileURL.endsWith('.json')) {
const m = new SyntheticModule(
['default'],
() => {
const result = JSON.parse(code)
m.setExport('default', result)
},
)
this.moduleCache.set(fileUrl, m)
this.moduleCache.set(fileURL, m)
return m
}
const m = new SourceTextModule(
code,
{
identifier: fileUrl,
identifier: fileURL,
context: this.context,
importModuleDynamically: this.executor.importModuleDynamically,
initializeImportMeta: (meta, mod) => {
Expand All @@ -76,7 +82,7 @@ export class EsmExecutor {
},
},
)
this.moduleCache.set(fileUrl, m)
this.moduleCache.set(fileURL, m)
return m
}

Expand Down
15 changes: 12 additions & 3 deletions packages/vitest/src/runtime/vm/file-map.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
import { readFileSync } from 'node:fs'
import { promises as fs, readFileSync } from 'node:fs'

export class FileMap {
private fsCache = new Map<string, string>()
private fsBufferCache = new Map<string, Buffer>()

public async readFileAsync(path: string) {
const cached = this.fsCache.get(path)
if (cached != null)
return cached
const source = await fs.readFile(path, 'utf-8')
this.fsCache.set(path, source)
return source
}

public readFile(path: string) {
const cached = this.fsCache.get(path)
if (cached)
if (cached != null)
return cached
const source = readFileSync(path, 'utf-8')
this.fsCache.set(path, source)
Expand All @@ -15,7 +24,7 @@ export class FileMap {

public readBuffer(path: string) {
const cached = this.fsBufferCache.get(path)
if (cached)
if (cached != null)
return cached
const buffer = readFileSync(path)
this.fsBufferCache.set(path, buffer)
Expand Down
35 changes: 25 additions & 10 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions test/core/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export default defineConfig({
port: 3022,
},
test: {
reporters: ['verbose'],
api: {
port: 3023,
},
Expand Down
3 changes: 2 additions & 1 deletion test/reporters/fixtures/console.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ describe('suite', () => {
console.error('nested suite stderr afterAll')
})

test('test', () => {
test('test', async () => {
await new Promise((resolve) => setTimeout(resolve, 100))
expect(true).toBe(true)
})
})
Expand Down
31 changes: 22 additions & 9 deletions test/reporters/tests/console.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,37 +4,50 @@ import { runVitest } from '../../test-utils'

test('should print logs correctly', async () => {
const filename = resolve('./fixtures/console.test.ts')
const { stdout, stderr } = await runVitest({ root: './fixtures' }, [filename])
const { stdout, stderr } = await runVitest({ root: './fixtures', reporters: ['dot'] }, [filename])

expect(stdout).toBeTruthy()
expect(stderr).toBeTruthy()

expect(stdout).toContain(
`stdout | console.test.ts
global stdin beforeAll
stdout | console.test.ts > suite
suite stdin beforeAll
stdout | console.test.ts > suite > nested suite
nested suite stdin beforeAll`,
)

expect(stdout).toContain(
`stdout | console.test.ts > suite > nested suite
nested suite stdin beforeAll
nested suite stdin afterAll
stdout | console.test.ts > suite
suite stdin beforeAll
suite stdin afterAll
stdout | console.test.ts
global stdin beforeAll
global stdin afterAll
`,
global stdin afterAll`,
)

expect(stderr).toContain(
`stderr | console.test.ts > suite > nested suite
`stderr | console.test.ts
global stderr beforeAll
stderr | console.test.ts > suite
suite stderr beforeAll
stderr | console.test.ts > suite > nested suite
nested suite stderr beforeAll
stderr | console.test.ts > suite > nested suite
nested suite stderr afterAll
stderr | console.test.ts > suite
suite stderr beforeAll
suite stderr afterAll
stderr | console.test.ts
global stderr beforeAll
global stderr afterAll`,
)
})

0 comments on commit f2e15f7

Please sign in to comment.