|
| 1 | +const testSetup = require('../__shared__/test-setup'); |
| 2 | +const path = require('path'); |
| 3 | +const fs = require('fs'); |
| 4 | + |
| 5 | +test('Ignores node_modules when detecting TypeScript', async () => { |
| 6 | + // CRA build will check for TypeScript files by |
| 7 | + // globbing for src/**/*.ts however this shouldn't |
| 8 | + // include any node_modules directories within src. |
| 9 | + // See https://github.com/facebook/create-react-app/issues/5947 |
| 10 | + |
| 11 | + const tsConfigPath = path.join(testSetup.testDirectory, 'tsconfig.json'); |
| 12 | + const tsPackagePath = [ |
| 13 | + testSetup.testDirectory, |
| 14 | + 'src', |
| 15 | + 'node_modules', |
| 16 | + 'package', |
| 17 | + 'index.ts', |
| 18 | + ]; |
| 19 | + const tsSrcPath = path.join(testSetup.testDirectory, 'src', 'index.ts'); |
| 20 | + |
| 21 | + // Step 1. |
| 22 | + // See if src/node_modules/package/index.ts is treated |
| 23 | + // as a JS project |
| 24 | + fs.mkdirSync(path.join(...tsPackagePath.slice(0, 2))); |
| 25 | + fs.mkdirSync(path.join(...tsPackagePath.slice(0, 3))); |
| 26 | + fs.mkdirSync(path.join(...tsPackagePath.slice(0, 4))); |
| 27 | + fs.writeFileSync(path.join(...tsPackagePath)); |
| 28 | + await testSetup.scripts.build(); |
| 29 | + expect(fs.existsSync(tsConfigPath)).toBe(false); |
| 30 | + |
| 31 | + // Step 2. |
| 32 | + // Add TS and ensure tsconfig.json is generated |
| 33 | + fs.writeFileSync(tsSrcPath); |
| 34 | + await testSetup.scripts.build(); |
| 35 | + expect(fs.existsSync(tsConfigPath)).toBe(true); |
| 36 | +}); |
0 commit comments