Skip to content

Commit

Permalink
Add test coverage (#1109)
Browse files Browse the repository at this point in the history
* WIP

* fix lint failures

* Add tests
  • Loading branch information
cspotcode authored Aug 12, 2020
1 parent e29ae04 commit 7cb6d57
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 1 deletion.
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'

0 comments on commit 7cb6d57

Please sign in to comment.