Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cspotcode committed Aug 12, 2020
1 parent 35be1d7 commit 98dc6f5
Showing 1 changed file with 49 additions and 2 deletions.
51 changes: 49 additions & 2 deletions 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 @@ -829,7 +875,8 @@ describe('ts-node', function () {
cwd: join(__dirname, '../tests/esm-import-http-url')
}, function (err, stdout, stderr) {
expect(err).to.not.equal(null)
expect(stderr).to.contain('sfaksdfjl')
// expect error from node's default resolver
expect(stderr).to.match(/Error \[ERR_UNSUPPORTED_ESM_URL_SCHEME\]:.*\n *at defaultResolve/)
return done()
})
})
Expand Down

0 comments on commit 98dc6f5

Please sign in to comment.