Skip to content

Commit ebe8bbd

Browse files
committed
simpler way of sharing tests between node and browser
1 parent c82db63 commit ebe8bbd

3 files changed

Lines changed: 28 additions & 24 deletions

File tree

tests/browser/index.test.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
import { test, expect } from '@playwright/test'
2-
import { launch } from '../common/index.test'
2+
import { tests } from '../common/index.test'
33

4-
launch({ expect, test })
4+
for (const { name, prepare, expected } of tests) {
5+
test(name, async () => {
6+
const result = await prepare()
7+
expect(result).toBe(expected)
8+
})
9+
}

tests/common/index.test.ts

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,16 @@
1-
import { test as pTest, expect as pExpect } from '@playwright/test'
2-
import { expect as vExpect } from 'vitest'
3-
41
import { parse } from '../../src'
52

6-
export function launch({ expect, test }: {
7-
expect: typeof pExpect
8-
test: typeof pTest
9-
} | {
10-
expect: typeof vExpect
11-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
12-
test: any
13-
}): void {
14-
test('parse', async () => {
15-
const text = 'hello, csvremote!!!'
16-
let result = ''
17-
for await (const chunk of parse(text, { chunkSize: 5, isUrl: false })) {
18-
result += chunk
19-
}
20-
expect(result).toBe(text)
21-
})
22-
}
3+
export const tests = [
4+
{
5+
name: 'parse',
6+
prepare: async () => {
7+
const text = 'hello, csvremote!!!'
8+
let result = ''
9+
for await (const chunk of parse(text, { chunkSize: 5, isUrl: false })) {
10+
result += chunk
11+
}
12+
return result
13+
},
14+
expected: 'hello, csvremote!!!',
15+
},
16+
]

tests/node/index.test.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
import { expect, test } from 'vitest'
2-
import { launch } from '../common/index.test'
2+
import { tests } from '../common/index.test'
33

4-
launch({ expect, test })
4+
for (const { name, prepare, expected } of tests) {
5+
test(name, async () => {
6+
const result = await prepare()
7+
expect(result).toBe(expected)
8+
})
9+
}

0 commit comments

Comments
 (0)