-
-
Notifications
You must be signed in to change notification settings - Fork 539
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
flatten and break up test suites into multiple files (#2015)
- Loading branch information
Showing
18 changed files
with
267 additions
and
248 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { lstatSync } from 'fs'; | ||
import { join } from 'path'; | ||
import { BIN_CWD_PATH, BIN_PATH, BIN_SCRIPT_PATH, createExec, ctxTsNode, TEST_DIR } from '../helpers'; | ||
import { context, expect } from '../testlib'; | ||
|
||
const exec = createExec({ | ||
cwd: TEST_DIR, | ||
}); | ||
|
||
const test = context(ctxTsNode); | ||
|
||
test('should locate tsconfig relative to entry-point by default', async () => { | ||
const r = await exec(`${BIN_PATH} ../a/index`, { | ||
cwd: join(TEST_DIR, 'cwd-and-script-mode/b'), | ||
}); | ||
expect(r.err).toBe(null); | ||
expect(r.stdout).toMatch(/plugin-a/); | ||
}); | ||
test('should locate tsconfig relative to entry-point via ts-node-script', async () => { | ||
const r = await exec(`${BIN_SCRIPT_PATH} ../a/index`, { | ||
cwd: join(TEST_DIR, 'cwd-and-script-mode/b'), | ||
}); | ||
expect(r.err).toBe(null); | ||
expect(r.stdout).toMatch(/plugin-a/); | ||
}); | ||
test('should locate tsconfig relative to entry-point with --script-mode', async () => { | ||
const r = await exec(`${BIN_PATH} --script-mode ../a/index`, { | ||
cwd: join(TEST_DIR, 'cwd-and-script-mode/b'), | ||
}); | ||
expect(r.err).toBe(null); | ||
expect(r.stdout).toMatch(/plugin-a/); | ||
}); | ||
test('should locate tsconfig relative to cwd via ts-node-cwd', async () => { | ||
const r = await exec(`${BIN_CWD_PATH} ../a/index`, { | ||
cwd: join(TEST_DIR, 'cwd-and-script-mode/b'), | ||
}); | ||
expect(r.err).toBe(null); | ||
expect(r.stdout).toMatch(/plugin-b/); | ||
}); | ||
test('should locate tsconfig relative to cwd in --cwd-mode', async () => { | ||
const r = await exec(`${BIN_PATH} --cwd-mode ../a/index`, { | ||
cwd: join(TEST_DIR, 'cwd-and-script-mode/b'), | ||
}); | ||
expect(r.err).toBe(null); | ||
expect(r.stdout).toMatch(/plugin-b/); | ||
}); | ||
test('should locate tsconfig relative to realpath, not symlink, when entrypoint is a symlink', async (t) => { | ||
if (lstatSync(join(TEST_DIR, 'main-realpath/symlink/symlink.tsx')).isSymbolicLink()) { | ||
const r = await exec(`${BIN_PATH} main-realpath/symlink/symlink.tsx`); | ||
expect(r.err).toBe(null); | ||
expect(r.stdout).toBe(''); | ||
} else { | ||
t.log('Skipping'); | ||
return; | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { ctxTsNode } from './helpers'; | ||
import { context, expect } from './testlib'; | ||
|
||
const test = context(ctxTsNode); | ||
|
||
test.suite('create', ({ contextEach }) => { | ||
const test = contextEach(async (t) => { | ||
return { | ||
service: t.context.tsNodeUnderTest.create({ | ||
compilerOptions: { target: 'es5' }, | ||
skipProject: true, | ||
}), | ||
}; | ||
}); | ||
|
||
test('should create generic compiler instances', (t) => { | ||
const output = t.context.service.compile('const x = 10', 'test.ts'); | ||
expect(output).toMatch('var x = 10;'); | ||
}); | ||
|
||
test.suite('should get type information', (test) => { | ||
test('given position of identifier', (t) => { | ||
expect(t.context.service.getTypeInfo('/**jsdoc here*/const x = 10', 'test.ts', 21)).toEqual({ | ||
comment: 'jsdoc here', | ||
name: 'const x: 10', | ||
}); | ||
}); | ||
test('given position that does not point to an identifier', (t) => { | ||
expect(t.context.service.getTypeInfo('/**jsdoc here*/const x = 10', 'test.ts', 0)).toEqual({ | ||
comment: '', | ||
name: '', | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.