|
| 1 | +import path from 'node:path'; |
| 2 | +import { fileURLToPath } from 'node:url'; |
| 3 | +import { describe, expect, it, rs } from '@rstest/core'; |
| 4 | +import { prepareFixtures, runRstestCli } from '../scripts'; |
| 5 | + |
| 6 | +const __filename = fileURLToPath(import.meta.url); |
| 7 | +const __dirname = path.dirname(__filename); |
| 8 | + |
| 9 | +rs.setConfig({ |
| 10 | + retry: 3, |
| 11 | +}); |
| 12 | + |
| 13 | +const getRerunSection = (stdout: string): string => { |
| 14 | + const match = stdout.match(/Test files to re-run.*?:\n([\s\S]*?)\n\n/); |
| 15 | + return match?.[1] ?? ''; |
| 16 | +}; |
| 17 | + |
| 18 | +describe.skipIf(process.platform === 'win32')( |
| 19 | + 'watch environment comments', |
| 20 | + () => { |
| 21 | + it('should honor environment comments', async () => { |
| 22 | + const fixturesTargetPath = `${__dirname}/fixtures-test-environment-comment${process.env.RSTEST_OUTPUT_MODULE !== 'false' ? '-module' : ''}`; |
| 23 | + |
| 24 | + const { fs } = await prepareFixtures({ |
| 25 | + fixturesPath: `${__dirname}/fixtures-environment-comment`, |
| 26 | + fixturesTargetPath, |
| 27 | + }); |
| 28 | + |
| 29 | + const { cli } = await runRstestCli({ |
| 30 | + command: 'rstest', |
| 31 | + args: ['watch', '--disableConsoleIntercept'], |
| 32 | + options: { |
| 33 | + nodeOptions: { |
| 34 | + env: { DEBUG: 'rstest' }, |
| 35 | + cwd: fixturesTargetPath, |
| 36 | + }, |
| 37 | + }, |
| 38 | + }); |
| 39 | + |
| 40 | + await cli.waitForStdout('Tests 2 passed'); |
| 41 | + expect(cli.stdout).toMatch( |
| 42 | + 'Run all tests in project(rstest-environment-1).', |
| 43 | + ); |
| 44 | + expect(cli.stdout).toMatch( |
| 45 | + 'Run all tests in project(rstest-environment-2).', |
| 46 | + ); |
| 47 | + if (!cli.stdout.includes('Waiting for file changes...')) { |
| 48 | + await cli.waitForStdout('Waiting for file changes...'); |
| 49 | + } |
| 50 | + |
| 51 | + cli.resetStd(); |
| 52 | + fs.update(path.join(fixturesTargetPath, 'src/index.ts'), (content) => { |
| 53 | + return content.replace("'initial'", "'initial' as const"); |
| 54 | + }); |
| 55 | + |
| 56 | + await cli.waitForStdout('Test files to re-run'); |
| 57 | + await cli.waitForStdout('Tests 2 passed'); |
| 58 | + |
| 59 | + const rerunSection = getRerunSection(cli.stdout); |
| 60 | + expect(rerunSection).toMatch('index.test.ts'); |
| 61 | + expect(rerunSection).not.toMatch('node.test.ts'); |
| 62 | + |
| 63 | + cli.exec.kill(); |
| 64 | + }); |
| 65 | + }, |
| 66 | +); |
0 commit comments