Skip to content

Commit

Permalink
chore: move browser workspaces test
Browse files Browse the repository at this point in the history
  • Loading branch information
sheremet-va committed Aug 14, 2023
1 parent c1c8c17 commit 9f69ec8
Show file tree
Hide file tree
Showing 14 changed files with 214 additions and 109 deletions.
227 changes: 121 additions & 106 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions test/workspaces-browser/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
results.json
17 changes: 17 additions & 0 deletions test/workspaces-browser/globalTest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { readFile } from 'node:fs/promises'
import assert from 'node:assert/strict'

export async function teardown() {
const results = JSON.parse(await readFile('./results.json', 'utf-8'))

try {
assert.ok(results.success)
assert.equal(results.numTotalTestSuites, 3)
assert.equal(results.numTotalTests, 3)
assert.equal(results.numPassedTests, 3)
}
catch (err) {
console.error(err)
process.exit(1)
}
}
12 changes: 12 additions & 0 deletions test/workspaces-browser/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "@vitest/test-workspaces",
"type": "module",
"private": true,
"scripts": {
"test": "vitest run"
},
"devDependencies": {
"@vitest/browser": "workspace:^",
"vitest": "workspace:*"
}
}
6 changes: 6 additions & 0 deletions test/workspaces-browser/space_1/test/math.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { expect, test } from 'vitest'
import { sum } from '../../src/math'

test('3 + 3 = 6', () => {
expect(sum(3, 3)).toBe(6)
})
5 changes: 5 additions & 0 deletions test/workspaces-browser/space_1/test/node.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { expect, test } from 'vitest'

test('window is undefined', () => {
expect(globalThis.window).toBeUndefined()
})
7 changes: 7 additions & 0 deletions test/workspaces-browser/space_1/vite.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { defineProject } from 'vitest/config'

export default defineProject({
test: {
name: 'space_1',
},
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { defineProject } from 'vitest/config'

export default defineProject({
test: {
name: 'space_1',
environment: 'happy-dom',
},
})
14 changes: 14 additions & 0 deletions test/workspaces-browser/src/math.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/* eslint-disable unused-imports/no-unused-vars */
export function sum(a: number, b: number) {
if (a === 3 && b === 4) {
// This should be uncovered
return 7
}

return a + b
}

function uncoveredFunction() {
// This should be uncovered
return 1
}
15 changes: 15 additions & 0 deletions test/workspaces-browser/vitest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { defineConfig } from 'vitest/config'

if (process.env.TEST_WATCH) {
// Patch stdin on the process so that we can fake it to seem like a real interactive terminal and pass the TTY checks
process.stdin.isTTY = true
process.stdin.setRawMode = () => process.stdin
}

export default defineConfig({
test: {
reporters: ['default', 'json'],
outputFile: './results.json',
globalSetup: './globalTest.ts',
},
})
5 changes: 5 additions & 0 deletions test/workspaces-browser/vitest.workspace.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { defineWorkspace } from 'vitest/config'

export default defineWorkspace([
'./space_*/*.config.ts',
])
6 changes: 3 additions & 3 deletions test/workspaces/globalTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ export async function teardown() {

try {
assert.ok(results.success)
assert.equal(results.numTotalTestSuites, 7)
assert.equal(results.numTotalTests, 8)
assert.equal(results.numPassedTests, 8)
assert.equal(results.numTotalTestSuites, 6)
assert.equal(results.numTotalTests, 7)
assert.equal(results.numPassedTests, 7)

const shared = results.testResults.filter((r: any) => r.name.includes('space_shared/test.spec.ts'))

Expand Down

0 comments on commit 9f69ec8

Please sign in to comment.