|
1 | 1 | import { join } from 'node:path';
|
2 |
| -import { expect, it } from '@rstest/core'; |
| 2 | +import { describe, expect, it } from '@rstest/core'; |
3 | 3 | import fs from 'fs-extra';
|
4 | 4 | import { runRstestCli } from '../scripts';
|
5 | 5 |
|
6 |
| -it('coverage-istanbul', async () => { |
7 |
| - const { expectExecSuccess, expectLog, cli } = await runRstestCli({ |
8 |
| - command: 'rstest', |
9 |
| - args: ['run'], |
10 |
| - options: { |
11 |
| - nodeOptions: { |
12 |
| - cwd: join(__dirname, 'fixtures'), |
| 6 | +// TODO: swc-plugin-coverage-instrument `unstableExclude` option should works in windows |
| 7 | +describe.skipIf(process.platform === 'win32')('test coverage-istanbul', () => { |
| 8 | + it('coverage-istanbul', async () => { |
| 9 | + const { expectExecSuccess, expectLog, cli } = await runRstestCli({ |
| 10 | + command: 'rstest', |
| 11 | + args: ['run'], |
| 12 | + options: { |
| 13 | + nodeOptions: { |
| 14 | + cwd: join(__dirname, 'fixtures'), |
| 15 | + }, |
13 | 16 | },
|
14 |
| - }, |
| 17 | + }); |
| 18 | + |
| 19 | + await expectExecSuccess(); |
| 20 | + |
| 21 | + const logs = cli.stdout.split('\n').filter(Boolean); |
| 22 | + |
| 23 | + expectLog('Coverage enabled with istanbul', logs); |
| 24 | + |
| 25 | + // test coverage |
| 26 | + expect( |
| 27 | + logs.find( |
| 28 | + (log) => |
| 29 | + log.includes('index.test.ts') && |
| 30 | + log.replaceAll(' ', '').includes('100|100|100|100'), |
| 31 | + ), |
| 32 | + ).toBeFalsy(); |
| 33 | + |
| 34 | + expect( |
| 35 | + logs.find( |
| 36 | + (log) => |
| 37 | + log.includes('rstest.setup.ts') && |
| 38 | + log.replaceAll(' ', '').includes('100|100|100|100'), |
| 39 | + ), |
| 40 | + ).toBeFalsy(); |
| 41 | + |
| 42 | + expect( |
| 43 | + logs.find( |
| 44 | + (log) => |
| 45 | + log.includes('index.ts') && |
| 46 | + log.replaceAll(' ', '').includes('100|100|100|100'), |
| 47 | + ), |
| 48 | + ).toBeTruthy(); |
| 49 | + expect( |
| 50 | + logs.find((log) => log.includes('string.ts'))?.replaceAll(' ', ''), |
| 51 | + ).toMatchInlineSnapshot(`"string.ts|93.75|100|83.33|92.85|7"`); |
| 52 | + |
| 53 | + expect( |
| 54 | + logs.find((log) => log.includes('All files'))?.replaceAll(' ', ''), |
| 55 | + ).toMatchInlineSnapshot(`"Allfiles|98.33|100|94.44|98.21|"`); |
| 56 | + |
| 57 | + // text reporter |
| 58 | + expectLog('% Stmts', logs); |
| 59 | + |
| 60 | + // html reporter |
| 61 | + expect( |
| 62 | + fs.existsSync(join(__dirname, 'fixtures/coverage/index.html')), |
| 63 | + ).toBeTruthy(); |
| 64 | + |
| 65 | + // clover reporter |
| 66 | + expect( |
| 67 | + fs.existsSync(join(__dirname, 'fixtures/coverage/clover.xml')), |
| 68 | + ).toBeTruthy(); |
| 69 | + |
| 70 | + // json reporter |
| 71 | + expect( |
| 72 | + fs.existsSync(join(__dirname, 'fixtures/coverage/coverage-final.json')), |
| 73 | + ).toBeTruthy(); |
15 | 74 | });
|
16 | 75 |
|
17 |
| - await expectExecSuccess(); |
18 |
| - |
19 |
| - const logs = cli.stdout.split('\n').filter(Boolean); |
20 |
| - |
21 |
| - expectLog('Coverage enabled with istanbul', logs); |
22 |
| - |
23 |
| - // test coverage |
24 |
| - expect( |
25 |
| - logs.find( |
26 |
| - (log) => |
27 |
| - log.includes('index.ts') && |
28 |
| - log.replaceAll(' ', '').includes('100|100|100|100'), |
29 |
| - ), |
30 |
| - ).toBeTruthy(); |
31 |
| - expect( |
32 |
| - logs.find( |
33 |
| - (log) => |
34 |
| - log.includes('string.ts') && |
35 |
| - log.replaceAll(' ', '').includes('93.75|100|83.33|92.85|7'), |
36 |
| - ), |
37 |
| - ).toBeTruthy(); |
38 |
| - // TODO: should not include test files |
39 |
| - expect( |
40 |
| - logs.find( |
41 |
| - (log) => |
42 |
| - log.includes('All files') && |
43 |
| - log.replaceAll(' ', '').includes('99.43|100|98.68|99.41'), |
44 |
| - ), |
45 |
| - ).toBeTruthy(); |
46 |
| - |
47 |
| - // text reporter |
48 |
| - expectLog('% Stmts', logs); |
49 |
| - |
50 |
| - // html reporter |
51 |
| - expect( |
52 |
| - fs.existsSync(join(__dirname, 'fixtures/coverage/index.html')), |
53 |
| - ).toBeTruthy(); |
54 |
| - |
55 |
| - // clover reporter |
56 |
| - expect( |
57 |
| - fs.existsSync(join(__dirname, 'fixtures/coverage/clover.xml')), |
58 |
| - ).toBeTruthy(); |
59 |
| - |
60 |
| - // json reporter |
61 |
| - expect( |
62 |
| - fs.existsSync(join(__dirname, 'fixtures/coverage/coverage-final.json')), |
63 |
| - ).toBeTruthy(); |
64 |
| -}); |
65 |
| - |
66 |
| -it('coverage-istanbul with custom options', async () => { |
67 |
| - const { expectExecSuccess, expectLog, cli } = await runRstestCli({ |
68 |
| - command: 'rstest', |
69 |
| - args: ['run', '-c', 'rstest.skipFull.config.ts'], |
70 |
| - options: { |
71 |
| - nodeOptions: { |
72 |
| - cwd: join(__dirname, 'fixtures'), |
| 76 | + it('coverage-istanbul with custom options', async () => { |
| 77 | + const { expectExecSuccess, expectLog, cli } = await runRstestCli({ |
| 78 | + command: 'rstest', |
| 79 | + args: ['run', '-c', 'rstest.skipFull.config.ts'], |
| 80 | + options: { |
| 81 | + nodeOptions: { |
| 82 | + cwd: join(__dirname, 'fixtures'), |
| 83 | + }, |
73 | 84 | },
|
74 |
| - }, |
75 |
| - }); |
| 85 | + }); |
76 | 86 |
|
77 |
| - await expectExecSuccess(); |
78 |
| - |
79 |
| - const logs = cli.stdout.split('\n').filter(Boolean); |
80 |
| - |
81 |
| - expectLog('Coverage enabled with istanbul', logs); |
82 |
| - |
83 |
| - // test coverage |
84 |
| - expect( |
85 |
| - logs.find( |
86 |
| - (log) => |
87 |
| - log.includes('index.ts') && |
88 |
| - log.replaceAll(' ', '').includes('100|100|100|100'), |
89 |
| - ), |
90 |
| - ).toBeFalsy(); |
91 |
| - expect( |
92 |
| - logs.find( |
93 |
| - (log) => |
94 |
| - log.includes('string.ts') && |
95 |
| - log.replaceAll(' ', '').includes('93.75|100|83.33|92.85|7'), |
96 |
| - ), |
97 |
| - ).toBeTruthy(); |
98 |
| - |
99 |
| - // text reporter |
100 |
| - expectLog('% Stmts', logs); |
101 |
| - |
102 |
| - expect( |
103 |
| - fs.existsSync(join(__dirname, 'fixtures/coverage/index.html')), |
104 |
| - ).toBeFalsy(); |
105 |
| -}); |
| 87 | + await expectExecSuccess(); |
106 | 88 |
|
107 |
| -it('coverage-istanbul with custom reportsDirectory', async () => { |
108 |
| - const { expectExecSuccess, expectLog, cli } = await runRstestCli({ |
109 |
| - command: 'rstest', |
110 |
| - args: ['run', '-c', 'rstest.reportsDirectory.config.ts'], |
111 |
| - options: { |
112 |
| - nodeOptions: { |
113 |
| - cwd: join(__dirname, 'fixtures'), |
114 |
| - }, |
115 |
| - }, |
| 89 | + const logs = cli.stdout.split('\n').filter(Boolean); |
| 90 | + |
| 91 | + expectLog('Coverage enabled with istanbul', logs); |
| 92 | + |
| 93 | + // test coverage |
| 94 | + expect(logs.find((log) => log.includes('index.ts'))).toBeFalsy(); |
| 95 | + expect( |
| 96 | + logs.find((log) => log.includes('string.ts'))?.replaceAll(' ', ''), |
| 97 | + ).toMatchInlineSnapshot(`"string.ts|93.75|100|83.33|92.85|7"`); |
| 98 | + |
| 99 | + // text reporter |
| 100 | + expectLog('% Stmts', logs); |
| 101 | + |
| 102 | + expect( |
| 103 | + fs.existsSync(join(__dirname, 'fixtures/coverage/index.html')), |
| 104 | + ).toBeFalsy(); |
116 | 105 | });
|
117 | 106 |
|
118 |
| - await expectExecSuccess(); |
| 107 | + it('coverage-istanbul with custom reportsDirectory', async () => { |
| 108 | + const { expectExecSuccess, expectLog, cli } = await runRstestCli({ |
| 109 | + command: 'rstest', |
| 110 | + args: ['run', '-c', 'rstest.reportsDirectory.config.ts'], |
| 111 | + options: { |
| 112 | + nodeOptions: { |
| 113 | + cwd: join(__dirname, 'fixtures'), |
| 114 | + }, |
| 115 | + }, |
| 116 | + }); |
| 117 | + |
| 118 | + await expectExecSuccess(); |
119 | 119 |
|
120 |
| - const logs = cli.stdout.split('\n').filter(Boolean); |
| 120 | + const logs = cli.stdout.split('\n').filter(Boolean); |
121 | 121 |
|
122 |
| - expectLog('Coverage enabled with istanbul', logs); |
| 122 | + expectLog('Coverage enabled with istanbul', logs); |
123 | 123 |
|
124 |
| - expect( |
125 |
| - fs.existsSync(join(__dirname, 'fixtures/test-temp-coverage/index.html')), |
126 |
| - ).toBeTruthy(); |
| 124 | + expect( |
| 125 | + fs.existsSync(join(__dirname, 'fixtures/test-temp-coverage/index.html')), |
| 126 | + ).toBeTruthy(); |
| 127 | + }); |
127 | 128 | });
|
0 commit comments