Skip to content

Commit

Permalink
test: Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Septh committed Feb 3, 2024
1 parent fbddcaa commit b66ccd4
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
8 changes: 6 additions & 2 deletions test/02.sourcemap.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,14 @@ interface Unused {
}

describe("SourceMap v3 support", () => {
it("correctly maps stack traces back to original TS code", () => {
// Test currently disabled as it turns out that Sucrase guarantees
// that line numbers are the same before and after transpile,
// making the test completely irrelevant.
// See https://github.com/alangpierce/sucrase/issues/654#issuecomment-945491876
it.skip("correctly maps stack traces back to original TS code", () => {
let stack = ''
try {
throw new Error('Stack trace should show line 15, column 19.')
throw new Error('Stack trace should show line 19, column 19.')
}
catch(e) {
stack = (e as Error).stack ?? ''
Expand Down
14 changes: 13 additions & 1 deletion test/esm/01.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { describe, test } from 'node:test'
import assert from 'node:assert'
import path from 'node:path'
import { pathToFileURL } from 'node:url'
import { createRequire } from 'node:module'

describe("A .ts script inside a { type: 'module' } directory is ESM", () => {

Expand Down Expand Up @@ -30,7 +31,7 @@ describe("A .ts script inside a { type: 'module' } directory is ESM", () => {
test("require() does not exist", () => {
let threw = false
try {
require('./foo.ts')
require('./foo.cts')
}
catch(e) {
threw = e instanceof ReferenceError
Expand All @@ -47,4 +48,15 @@ describe("A .ts script inside a { type: 'module' } directory is ESM", () => {
catch {}
assert.strictEqual(url, pathToFileURL(path.resolve('test', 'esm', '01.test.ts')).href)
})

test("createRequire() works", () => {
let worked = true
try {
createRequire(import.meta.url)('./foo.cts')
}
catch(e) {
worked = false
}
assert.ok(worked)
})
})
3 changes: 0 additions & 3 deletions test/esm/02.test.cts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ describe("A .cts script inside a { type: 'module' } directory is CJS", () => {
it("require() is available", () => {
const foo = require('./foo.cts')
assert.strictEqual(foo, 'foo')

// const bar = require('./bar.cts')
// assert.strictEqual(bar, 'bar')
})

//
Expand Down

0 comments on commit b66ccd4

Please sign in to comment.