|
2 | 2 | import process from 'node:process'; |
3 | 3 | import fs from 'node:fs/promises'; |
4 | 4 | import path from 'node:path'; |
5 | | -import {availableParallelism} from 'node:os'; |
| 5 | +import {availableParallelism, tmpdir} from 'node:os'; |
6 | 6 | import test, {describe, type TestContext} from 'node:test'; |
7 | 7 | import assert from 'node:assert/strict'; |
8 | 8 | import dedent from 'dedent'; |
@@ -52,6 +52,25 @@ describe('xo CLI', {concurrency: availableParallelism()}, () => { |
52 | 52 | assert.ok(stdout.includes(ignoredFileWarningMessage)); |
53 | 53 | }); |
54 | 54 |
|
| 55 | + test('xo warns when the project TypeScript is older than the bundled version', async t => { |
| 56 | + const cwd = await fs.mkdtemp(path.join(tmpdir(), 'xo-ts-version-')); |
| 57 | + t.after(async () => { |
| 58 | + await fs.rm(cwd, {recursive: true, force: true}); |
| 59 | + }); |
| 60 | + |
| 61 | + await fs.writeFile(path.join(cwd, 'package.json'), JSON.stringify({type: 'module', name: 'ts-version-test'}), 'utf8'); |
| 62 | + await fs.writeFile(path.join(cwd, 'tsconfig.json'), '{}', 'utf8'); |
| 63 | + await fs.writeFile(path.join(cwd, 'foo.ts'), dedent`export const x = 1;\n`, 'utf8'); |
| 64 | + |
| 65 | + // Simulate an older-major project-level TypeScript so the version-mismatch warning triggers. |
| 66 | + await fs.mkdir(path.join(cwd, 'node_modules', 'typescript'), {recursive: true}); |
| 67 | + await fs.writeFile(path.join(cwd, 'node_modules', 'typescript', 'package.json'), JSON.stringify({name: 'typescript', version: '5.0.0'}), 'utf8'); |
| 68 | + |
| 69 | + const {stderr} = await $({reject: false})`node ./dist/cli --cwd ${cwd} foo.ts`; |
| 70 | + assert.ok(stderr.includes('XO bundles TypeScript')); |
| 71 | + assert.ok(stderr.includes('5.0.0')); |
| 72 | + }); |
| 73 | + |
55 | 74 | test('xo fails with exit code 2 for missing custom suppressions file', async t => { |
56 | 75 | const cwd = await createProject(t); |
57 | 76 | const filePath = path.join(cwd, 'test.js'); |
|
0 commit comments