Skip to content

Commit 89a266d

Browse files
authored
flatten and break up test suites into multiple files (#2015)
1 parent 1a12d66 commit 89a266d

18 files changed

+267
-248
lines changed
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
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+
});

src/test/configuration/tsnode-opts-from-tsconfig.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { BIN_PATH } from '../helpers/paths';
2-
import { createExec } from '../exec-helpers';
2+
import { createExec } from '../helpers/exec';
33
import { TEST_DIR } from '../helpers/paths';
44
import { context, expect } from '../testlib';
55
import { join, resolve } from 'path';

src/test/create.spec.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { ctxTsNode } from './helpers';
2+
import { context, expect } from './testlib';
3+
4+
const test = context(ctxTsNode);
5+
6+
test.suite('create', ({ contextEach }) => {
7+
const test = contextEach(async (t) => {
8+
return {
9+
service: t.context.tsNodeUnderTest.create({
10+
compilerOptions: { target: 'es5' },
11+
skipProject: true,
12+
}),
13+
};
14+
});
15+
16+
test('should create generic compiler instances', (t) => {
17+
const output = t.context.service.compile('const x = 10', 'test.ts');
18+
expect(output).toMatch('var x = 10;');
19+
});
20+
21+
test.suite('should get type information', (test) => {
22+
test('given position of identifier', (t) => {
23+
expect(t.context.service.getTypeInfo('/**jsdoc here*/const x = 10', 'test.ts', 21)).toEqual({
24+
comment: 'jsdoc here',
25+
name: 'const x: 10',
26+
});
27+
});
28+
test('given position that does not point to an identifier', (t) => {
29+
expect(t.context.service.getTypeInfo('/**jsdoc here*/const x = 10', 'test.ts', 0)).toEqual({
30+
comment: '',
31+
name: '',
32+
});
33+
});
34+
});
35+
});

src/test/esm-loader.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,16 @@ import {
1111
CMD_ESM_LOADER_WITHOUT_PROJECT,
1212
CMD_TS_NODE_WITHOUT_PROJECT_FLAG,
1313
ctxTsNode,
14-
delay,
1514
nodeSupportsImportAssertions,
1615
nodeSupportsUnflaggedJsonImports,
1716
nodeUsesNewHooksApi,
1817
resetNodeEnvironment,
1918
TEST_DIR,
2019
tsSupportsImportAssertions,
21-
tsSupportsStableNodeNextNode16,
20+
createExec,
21+
createSpawn,
22+
ExecReturn,
2223
} from './helpers';
23-
import { createExec, createSpawn, ExecReturn } from './exec-helpers';
2424
import { join, resolve } from 'path';
2525
import * as expect from 'expect';
2626
import type { NodeLoaderHooksAPI2 } from '../';

src/test/exec-helpers.ts renamed to src/test/helpers/exec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { ChildProcess, ExecException, ExecOptions, SpawnOptions } from 'child_process';
22
import { exec as childProcessExec, spawn as childProcessSpawn } from 'child_process';
33
import { ExpectStream, expectStream } from '@cspotcode/expect-stream';
4-
import { expect } from './testlib';
4+
import { expect } from '../testlib';
55

66
export type ExecReturn = Promise<ExecResult> & { child: ChildProcess };
77
export interface ExecResult {

src/test/helpers/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ export * from './paths';
55
export * from './command-lines';
66
export * from './reset-node-environment';
77
export * from './version-checks';
8+
export * from './exec';

0 commit comments

Comments
 (0)