|
| 1 | +import { lstatSync } from 'fs'; |
| 2 | +import { join } from 'path'; |
| 3 | +import { BIN_CWD_PATH, BIN_PATH, BIN_SCRIPT_PATH, createExec, ctxTsNode, TEST_DIR } from '../helpers'; |
| 4 | +import { context, expect } from '../testlib'; |
| 5 | + |
| 6 | +const exec = createExec({ |
| 7 | + cwd: TEST_DIR, |
| 8 | +}); |
| 9 | + |
| 10 | +const test = context(ctxTsNode); |
| 11 | + |
| 12 | +test('should locate tsconfig relative to entry-point by default', async () => { |
| 13 | + const r = await exec(`${BIN_PATH} ../a/index`, { |
| 14 | + cwd: join(TEST_DIR, 'cwd-and-script-mode/b'), |
| 15 | + }); |
| 16 | + expect(r.err).toBe(null); |
| 17 | + expect(r.stdout).toMatch(/plugin-a/); |
| 18 | +}); |
| 19 | +test('should locate tsconfig relative to entry-point via ts-node-script', async () => { |
| 20 | + const r = await exec(`${BIN_SCRIPT_PATH} ../a/index`, { |
| 21 | + cwd: join(TEST_DIR, 'cwd-and-script-mode/b'), |
| 22 | + }); |
| 23 | + expect(r.err).toBe(null); |
| 24 | + expect(r.stdout).toMatch(/plugin-a/); |
| 25 | +}); |
| 26 | +test('should locate tsconfig relative to entry-point with --script-mode', async () => { |
| 27 | + const r = await exec(`${BIN_PATH} --script-mode ../a/index`, { |
| 28 | + cwd: join(TEST_DIR, 'cwd-and-script-mode/b'), |
| 29 | + }); |
| 30 | + expect(r.err).toBe(null); |
| 31 | + expect(r.stdout).toMatch(/plugin-a/); |
| 32 | +}); |
| 33 | +test('should locate tsconfig relative to cwd via ts-node-cwd', async () => { |
| 34 | + const r = await exec(`${BIN_CWD_PATH} ../a/index`, { |
| 35 | + cwd: join(TEST_DIR, 'cwd-and-script-mode/b'), |
| 36 | + }); |
| 37 | + expect(r.err).toBe(null); |
| 38 | + expect(r.stdout).toMatch(/plugin-b/); |
| 39 | +}); |
| 40 | +test('should locate tsconfig relative to cwd in --cwd-mode', async () => { |
| 41 | + const r = await exec(`${BIN_PATH} --cwd-mode ../a/index`, { |
| 42 | + cwd: join(TEST_DIR, 'cwd-and-script-mode/b'), |
| 43 | + }); |
| 44 | + expect(r.err).toBe(null); |
| 45 | + expect(r.stdout).toMatch(/plugin-b/); |
| 46 | +}); |
| 47 | +test('should locate tsconfig relative to realpath, not symlink, when entrypoint is a symlink', async (t) => { |
| 48 | + if (lstatSync(join(TEST_DIR, 'main-realpath/symlink/symlink.tsx')).isSymbolicLink()) { |
| 49 | + const r = await exec(`${BIN_PATH} main-realpath/symlink/symlink.tsx`); |
| 50 | + expect(r.err).toBe(null); |
| 51 | + expect(r.stdout).toBe(''); |
| 52 | + } else { |
| 53 | + t.log('Skipping'); |
| 54 | + return; |
| 55 | + } |
| 56 | +}); |
0 commit comments