Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test coverage #1109

Merged
merged 4 commits into from
Aug 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 58 additions & 1 deletion src/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ before(async function () {

describe('ts-node', function () {
const cmd = `"${BIN_PATH}" --project "${PROJECT}"`
const cmdNoProject = `"${BIN_PATH}"`

this.timeout(10000)

Expand Down Expand Up @@ -88,6 +89,32 @@ describe('ts-node', function () {
})
})

it('shows usage via --help', function (done) {
exec(`${cmdNoProject} --help`, function (err, stdout) {
expect(err).to.equal(null)
expect(stdout).to.match(/Usage: ts-node /)
return done()
})
})
it('shows version via -v', function (done) {
exec(`${cmdNoProject} -v`, function (err, stdout) {
expect(err).to.equal(null)
expect(stdout.trim()).to.equal('v' + testsDirRequire('ts-node/package').version)
return done()
})
})
it('shows version of compiler via -vv', function (done) {
exec(`${cmdNoProject} -vv`, function (err, stdout) {
expect(err).to.equal(null)
expect(stdout.trim()).to.equal(
`ts-node v${ testsDirRequire('ts-node/package').version }\n` +
`node ${ process.version }\n` +
`compiler v${ testsDirRequire('typescript/package').version }`
)
return done()
})
})

it('should register via cli', function (done) {
exec(`node -r ts-node/register hello-world.ts`, {
cwd: TEST_DIR
Expand Down Expand Up @@ -727,11 +754,30 @@ describe('ts-node', function () {
})

describe('create', () => {
let service: tsNodeTypes.Register
before(() => {
service = create({ compilerOptions: { target: 'es5' }, skipProject: true })
})

it('should create generic compiler instances', () => {
const service = create({ compilerOptions: { target: 'es5' }, skipProject: true })
const output = service.compile('const x = 10', 'test.ts')
expect(output).to.contain('var x = 10;')
})

describe('should get type information', () => {
it('given position of identifier', () => {
expect(service.getTypeInfo('/**jsdoc here*/const x = 10', 'test.ts', 21)).to.deep.equal({
comment: 'jsdoc here',
name: 'const x: 10'
})
})
it('given position that does not point to an identifier', () => {
expect(service.getTypeInfo('/**jsdoc here*/const x = 10', 'test.ts', 0)).to.deep.equal({
comment: '',
name: ''
})
})
})
})

describe('issue #1098', () => {
Expand Down Expand Up @@ -824,6 +870,17 @@ describe('ts-node', function () {
})
})

it('defers to fallback loaders when URL should not be handled by ts-node', function (done) {
exec(`${cmd} index.mjs`, {
cwd: join(__dirname, '../tests/esm-import-http-url')
}, function (err, stdout, stderr) {
expect(err).to.not.equal(null)
// expect error from node's default resolver
expect(stderr).to.match(/Error \[ERR_UNSUPPORTED_ESM_URL_SCHEME\]:.*\n *at defaultResolve/)
return done()
})
})

it('should support transpile only mode via dedicated loader entrypoint', (done) => {
exec(`${cmd}/transpile-only index.ts`, { cwd: join(__dirname, '../tests/esm-transpile-only') }, function (err, stdout) {
expect(err).to.equal(null)
Expand Down
1 change: 1 addition & 0 deletions tests/esm-import-http-url/index.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import 'http://example.com/this-url-should-be-ignored-by-our-esm-loader.js'