diff --git a/.eslintrc.js b/.eslintrc.js index 29a0d66..f8c4211 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -18,6 +18,12 @@ module.exports = { 'no-constant-condition': 'off', 'no-unused-labels': 'off', 'prefer-rest-params': 'off', + 'prefer-const': [ + 'error', + { + destructuring: 'all', + }, + ], }, overrides: [ { diff --git a/.github/workflows/nodejs.yml b/.github/workflows/nodejs.yml index 376dc24..e65a957 100644 --- a/.github/workflows/nodejs.yml +++ b/.github/workflows/nodejs.yml @@ -8,8 +8,8 @@ jobs: strategy: matrix: - latest-node-version: [16.x] - node-version: [16.x] + latest-node-version: [20.x] + node-version: [18.x, 20.x] steps: - uses: actions/checkout@v1 diff --git a/.mocharc.js b/.mocharc.js new file mode 100644 index 0000000..7951cd1 --- /dev/null +++ b/.mocharc.js @@ -0,0 +1,4 @@ +module.exports = { + spec: ['test/**/*.test.ts'], + 'node-option': ['import=tsx'], +}; diff --git a/ava.config.mjs b/ava.config.mjs deleted file mode 100644 index 06200d3..0000000 --- a/ava.config.mjs +++ /dev/null @@ -1,7 +0,0 @@ -export default { - extensions: { - ts: 'module', - }, - nodeArguments: ['--no-warnings', '--loader=tsx'], - files: ['test/**/*.test.ts'], -}; diff --git a/package-lock.json b/package-lock.json index 163c1f1..7a1dbb7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@jridgewell/trace-mapping", - "version": "0.3.22", + "version": "0.3.23", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@jridgewell/trace-mapping", - "version": "0.3.22", + "version": "0.3.23", "license": "MIT", "dependencies": { "@jridgewell/resolve-uri": "^3.1.0", diff --git a/package.json b/package.json index 2b11a94..c534654 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@jridgewell/trace-mapping", - "version": "0.3.22", + "version": "0.3.23", "description": "Trace the original position through a source map", "keywords": [ "source", @@ -44,24 +44,26 @@ "prepublishOnly": "npm run preversion", "preversion": "run-s test build", "test": "run-s -n test:lint test:only", - "test:debug": "ava debug", + "test:debug": "mocha --inspect-brk", "test:lint": "run-s -n test:lint:*", "test:lint:prettier": "prettier --check '{src,test}/**/*.ts' '**/*.md'", "test:lint:ts": "eslint '{src,test}/**/*.ts'", - "test:only": "c8 ava", - "test:watch": "ava --watch" + "test:only": "c8 mocha", + "test:watch": "mocha --watch" }, "devDependencies": { "@rollup/plugin-typescript": "11.1.6", + "@types/mocha": "10.0.6", + "@types/node": "20.11.20", "@typescript-eslint/eslint-plugin": "6.18.1", "@typescript-eslint/parser": "6.18.1", - "ava": "6.0.1", "benchmark": "2.1.4", "c8": "9.0.0", "esbuild": "0.19.11", "eslint": "8.56.0", "eslint-config-prettier": "9.1.0", "eslint-plugin-no-only-tests": "3.1.0", + "mocha": "10.3.0", "npm-run-all": "4.1.5", "prettier": "3.1.1", "rollup": "4.9.4", diff --git a/src/by-source.ts b/src/by-source.ts index b4794f6..2af1cf0 100644 --- a/src/by-source.ts +++ b/src/by-source.ts @@ -34,13 +34,14 @@ export default function buildBySources( // segment should go. Either way, we want to insert after that. And there may be multiple // generated segments associated with an original location, so there may need to move several // indexes before we find where we need to insert. - const index = upperBound( + let index = upperBound( originalLine, sourceColumn, memoizedBinarySearch(originalLine, sourceColumn, memo, sourceLine), ); - insert(originalLine, (memo.lastIndex = index + 1), [sourceColumn, i, seg[COLUMN]]); + memo.lastIndex = ++index; + insert(originalLine, index, [sourceColumn, i, seg[COLUMN]]); } } diff --git a/src/trace-mapping.ts b/src/trace-mapping.ts index 780ea1b..157f299 100644 --- a/src/trace-mapping.ts +++ b/src/trace-mapping.ts @@ -61,317 +61,260 @@ export type { SourceNeedle, } from './types'; +interface PublicMap { + _encoded: TraceMap['_encoded']; + _decoded: TraceMap['_decoded']; + _decodedMemo: TraceMap['_decodedMemo']; + _bySources: TraceMap['_bySources']; + _bySourceMemos: TraceMap['_bySourceMemos']; +} + const LINE_GTR_ZERO = '`line` must be greater than 0 (lines start at line 1)'; const COL_GTR_EQ_ZERO = '`column` must be greater than or equal to 0 (columns start at column 0)'; export const LEAST_UPPER_BOUND = -1; export const GREATEST_LOWER_BOUND = 1; +export { AnyMap } from './any-map'; + +export class TraceMap implements SourceMap { + declare version: SourceMapV3['version']; + declare file: SourceMapV3['file']; + declare names: SourceMapV3['names']; + declare sourceRoot: SourceMapV3['sourceRoot']; + declare sources: SourceMapV3['sources']; + declare sourcesContent: SourceMapV3['sourcesContent']; + + declare resolvedSources: string[]; + private declare _encoded: string | undefined; + + private declare _decoded: SourceMapSegment[][] | undefined; + private declare _decodedMemo: MemoState; + + private declare _bySources: Source[] | undefined; + private declare _bySourceMemos: MemoState[] | undefined; + + constructor(map: SourceMapInput, mapUrl?: string | null) { + const isString = typeof map === 'string'; + + if (!isString && (map as unknown as { _decodedMemo: any })._decodedMemo) return map as TraceMap; + + const parsed = (isString ? JSON.parse(map) : map) as DecodedSourceMap | EncodedSourceMap; + + const { version, file, names, sourceRoot, sources, sourcesContent } = parsed; + this.version = version; + this.file = file; + this.names = names || []; + this.sourceRoot = sourceRoot; + this.sources = sources; + this.sourcesContent = sourcesContent; + + const from = resolve(sourceRoot || '', stripFilename(mapUrl)); + this.resolvedSources = sources.map((s) => resolve(s || '', from)); + + const { mappings } = parsed; + if (typeof mappings === 'string') { + this._encoded = mappings; + this._decoded = undefined; + } else { + this._encoded = undefined; + this._decoded = maybeSort(mappings, isString); + } + + this._decodedMemo = memoizedState(); + this._bySources = undefined; + this._bySourceMemos = undefined; + } +} + +/** + * Typescript doesn't allow friend access to private fields, so this just casts the map into a type + * with public access modifiers. + */ +function cast(map: unknown): PublicMap { + return map as any; +} + /** * Returns the encoded (VLQ string) form of the SourceMap's mappings field. */ -export let encodedMappings: (map: TraceMap) => EncodedSourceMap['mappings']; +export function encodedMappings(map: TraceMap): EncodedSourceMap['mappings'] { + return (cast(map)._encoded ??= encode(cast(map)._decoded!)); +} /** * Returns the decoded (array of lines of segments) form of the SourceMap's mappings field. */ -export let decodedMappings: (map: TraceMap) => Readonly; +export function decodedMappings(map: TraceMap): Readonly { + return (cast(map)._decoded ||= decode(cast(map)._encoded!)); +} /** * A low-level API to find the segment associated with a generated line/column (think, from a * stack trace). Line and column here are 0-based, unlike `originalPositionFor`. */ -export let traceSegment: ( +export function traceSegment( map: TraceMap, line: number, column: number, -) => Readonly | null; +): Readonly | null { + const decoded = decodedMappings(map); + + // It's common for parent source maps to have pointers to lines that have no + // mapping (like a "//# sourceMappingURL=") at the end of the child file. + if (line >= decoded.length) return null; + + const segments = decoded[line]; + const index = traceSegmentInternal( + segments, + cast(map)._decodedMemo, + line, + column, + GREATEST_LOWER_BOUND, + ); + + return index === -1 ? null : segments[index]; +} /** * A higher-level API to find the source/line/column associated with a generated line/column * (think, from a stack trace). Line is 1-based, but column is 0-based, due to legacy behavior in * `source-map` library. */ -export let originalPositionFor: ( +export function originalPositionFor( map: TraceMap, needle: Needle, -) => OriginalMapping | InvalidOriginalMapping; +): OriginalMapping | InvalidOriginalMapping { + let { line, column, bias } = needle; + line--; + if (line < 0) throw new Error(LINE_GTR_ZERO); + if (column < 0) throw new Error(COL_GTR_EQ_ZERO); + + const decoded = decodedMappings(map); + + // It's common for parent source maps to have pointers to lines that have no + // mapping (like a "//# sourceMappingURL=") at the end of the child file. + if (line >= decoded.length) return OMapping(null, null, null, null); + + const segments = decoded[line]; + const index = traceSegmentInternal( + segments, + cast(map)._decodedMemo, + line, + column, + bias || GREATEST_LOWER_BOUND, + ); + + if (index === -1) return OMapping(null, null, null, null); + + const segment = segments[index]; + if (segment.length === 1) return OMapping(null, null, null, null); + + const { names, resolvedSources } = map; + return OMapping( + resolvedSources[segment[SOURCES_INDEX]], + segment[SOURCE_LINE] + 1, + segment[SOURCE_COLUMN], + segment.length === 5 ? names[segment[NAMES_INDEX]] : null, + ); +} /** * Finds the generated line/column position of the provided source/line/column source position. */ -export let generatedPositionFor: ( +export function generatedPositionFor( map: TraceMap, needle: SourceNeedle, -) => GeneratedMapping | InvalidGeneratedMapping; +): GeneratedMapping | InvalidGeneratedMapping { + const { source, line, column, bias } = needle; + return generatedPosition(map, source, line, column, bias || GREATEST_LOWER_BOUND, false); +} /** * Finds all generated line/column positions of the provided source/line/column source position. */ -export let allGeneratedPositionsFor: (map: TraceMap, needle: SourceNeedle) => GeneratedMapping[]; +export function allGeneratedPositionsFor(map: TraceMap, needle: SourceNeedle): GeneratedMapping[] { + const { source, line, column, bias } = needle; + // SourceMapConsumer uses LEAST_UPPER_BOUND for some reason, so we follow suit. + return generatedPosition(map, source, line, column, bias || LEAST_UPPER_BOUND, true); +} /** * Iterates each mapping in generated position order. */ -export let eachMapping: (map: TraceMap, cb: (mapping: EachMapping) => void) => void; +export function eachMapping(map: TraceMap, cb: (mapping: EachMapping) => void): void { + const decoded = decodedMappings(map); + const { names, resolvedSources } = map; + + for (let i = 0; i < decoded.length; i++) { + const line = decoded[i]; + for (let j = 0; j < line.length; j++) { + const seg = line[j]; + + const generatedLine = i + 1; + const generatedColumn = seg[0]; + let source = null; + let originalLine = null; + let originalColumn = null; + let name = null; + if (seg.length !== 1) { + source = resolvedSources[seg[1]]; + originalLine = seg[2] + 1; + originalColumn = seg[3]; + } + if (seg.length === 5) name = names[seg[4]]; + + cb({ + generatedLine, + generatedColumn, + source, + originalLine, + originalColumn, + name, + } as EachMapping); + } + } +} /** * Retrieves the source content for a particular source, if its found. Returns null if not. */ -export let sourceContentFor: (map: TraceMap, source: string) => string | null; +export function sourceContentFor(map: TraceMap, source: string): string | null { + const { sources, resolvedSources, sourcesContent } = map; + if (sourcesContent == null) return null; + + let index = sources.indexOf(source); + if (index === -1) index = resolvedSources.indexOf(source); + + return index === -1 ? null : sourcesContent[index]; +} /** * A helper that skips sorting of the input map's mappings array, which can be expensive for larger * maps. */ -export let presortedDecodedMap: (map: DecodedSourceMap, mapUrl?: string) => TraceMap; +export function presortedDecodedMap(map: DecodedSourceMap, mapUrl?: string): TraceMap { + const tracer = new TraceMap(clone(map, []), mapUrl); + cast(tracer)._decoded = map.mappings; + return tracer; +} /** * Returns a sourcemap object (with decoded mappings) suitable for passing to a library that expects * a sourcemap, or to JSON.stringify. */ -export let decodedMap: ( +export function decodedMap( map: TraceMap, -) => Omit & { mappings: readonly SourceMapSegment[][] }; +): Omit & { mappings: readonly SourceMapSegment[][] } { + return clone(map, decodedMappings(map)); +} /** * Returns a sourcemap object (with encoded mappings) suitable for passing to a library that expects * a sourcemap, or to JSON.stringify. */ -export let encodedMap: (map: TraceMap) => EncodedSourceMap; - -export { AnyMap } from './any-map'; - -export class TraceMap implements SourceMap { - declare version: SourceMapV3['version']; - declare file: SourceMapV3['file']; - declare names: SourceMapV3['names']; - declare sourceRoot: SourceMapV3['sourceRoot']; - declare sources: SourceMapV3['sources']; - declare sourcesContent: SourceMapV3['sourcesContent']; - - declare resolvedSources: string[]; - private declare _encoded: string | undefined; - - private declare _decoded: SourceMapSegment[][] | undefined; - private declare _decodedMemo: MemoState; - - private declare _bySources: Source[] | undefined; - private declare _bySourceMemos: MemoState[] | undefined; - - constructor(map: SourceMapInput, mapUrl?: string | null) { - const isString = typeof map === 'string'; - - if (!isString && (map as unknown as { _decodedMemo: any })._decodedMemo) return map as TraceMap; - - const parsed = (isString ? JSON.parse(map) : map) as DecodedSourceMap | EncodedSourceMap; - - const { version, file, names, sourceRoot, sources, sourcesContent } = parsed; - this.version = version; - this.file = file; - this.names = names || []; - this.sourceRoot = sourceRoot; - this.sources = sources; - this.sourcesContent = sourcesContent; - - const from = resolve(sourceRoot || '', stripFilename(mapUrl)); - this.resolvedSources = sources.map((s) => resolve(s || '', from)); - - const { mappings } = parsed; - if (typeof mappings === 'string') { - this._encoded = mappings; - this._decoded = undefined; - } else { - this._encoded = undefined; - this._decoded = maybeSort(mappings, isString); - } - - this._decodedMemo = memoizedState(); - this._bySources = undefined; - this._bySourceMemos = undefined; - } - - static { - encodedMappings = (map) => { - return (map._encoded ??= encode(map._decoded!)); - }; - - decodedMappings = (map) => { - return (map._decoded ||= decode(map._encoded!)); - }; - - traceSegment = (map, line, column) => { - const decoded = decodedMappings(map); - - // It's common for parent source maps to have pointers to lines that have no - // mapping (like a "//# sourceMappingURL=") at the end of the child file. - if (line >= decoded.length) return null; - - const segments = decoded[line]; - const index = traceSegmentInternal( - segments, - map._decodedMemo, - line, - column, - GREATEST_LOWER_BOUND, - ); - - return index === -1 ? null : segments[index]; - }; - - originalPositionFor = (map, { line, column, bias }) => { - line--; - if (line < 0) throw new Error(LINE_GTR_ZERO); - if (column < 0) throw new Error(COL_GTR_EQ_ZERO); - - const decoded = decodedMappings(map); - - // It's common for parent source maps to have pointers to lines that have no - // mapping (like a "//# sourceMappingURL=") at the end of the child file. - if (line >= decoded.length) return OMapping(null, null, null, null); - - const segments = decoded[line]; - const index = traceSegmentInternal( - segments, - map._decodedMemo, - line, - column, - bias || GREATEST_LOWER_BOUND, - ); - - if (index === -1) return OMapping(null, null, null, null); - - const segment = segments[index]; - if (segment.length === 1) return OMapping(null, null, null, null); - - const { names, resolvedSources } = map; - return OMapping( - resolvedSources[segment[SOURCES_INDEX]], - segment[SOURCE_LINE] + 1, - segment[SOURCE_COLUMN], - segment.length === 5 ? names[segment[NAMES_INDEX]] : null, - ); - }; - - allGeneratedPositionsFor = (map, { source, line, column, bias }) => { - // SourceMapConsumer uses LEAST_UPPER_BOUND for some reason, so we follow suit. - return generatedPosition(map, source, line, column, bias || LEAST_UPPER_BOUND, true); - }; - - generatedPositionFor = (map, { source, line, column, bias }) => { - return generatedPosition(map, source, line, column, bias || GREATEST_LOWER_BOUND, false); - }; - - eachMapping = (map, cb) => { - const decoded = decodedMappings(map); - const { names, resolvedSources } = map; - - for (let i = 0; i < decoded.length; i++) { - const line = decoded[i]; - for (let j = 0; j < line.length; j++) { - const seg = line[j]; - - const generatedLine = i + 1; - const generatedColumn = seg[0]; - let source = null; - let originalLine = null; - let originalColumn = null; - let name = null; - if (seg.length !== 1) { - source = resolvedSources[seg[1]]; - originalLine = seg[2] + 1; - originalColumn = seg[3]; - } - if (seg.length === 5) name = names[seg[4]]; - - cb({ - generatedLine, - generatedColumn, - source, - originalLine, - originalColumn, - name, - } as EachMapping); - } - } - }; - - sourceContentFor = (map, source) => { - const { sources, resolvedSources, sourcesContent } = map; - if (sourcesContent == null) return null; - - let index = sources.indexOf(source); - if (index === -1) index = resolvedSources.indexOf(source); - - return index === -1 ? null : sourcesContent[index]; - }; - - presortedDecodedMap = (map, mapUrl) => { - const tracer = new TraceMap(clone(map, []), mapUrl); - tracer._decoded = map.mappings; - return tracer; - }; - - decodedMap = (map) => { - return clone(map, decodedMappings(map)); - }; - - encodedMap = (map) => { - return clone(map, encodedMappings(map)); - }; - - function generatedPosition( - map: TraceMap, - source: string, - line: number, - column: number, - bias: Bias, - all: false, - ): GeneratedMapping | InvalidGeneratedMapping; - function generatedPosition( - map: TraceMap, - source: string, - line: number, - column: number, - bias: Bias, - all: true, - ): GeneratedMapping[]; - function generatedPosition( - map: TraceMap, - source: string, - line: number, - column: number, - bias: Bias, - all: boolean, - ): GeneratedMapping | InvalidGeneratedMapping | GeneratedMapping[] { - line--; - if (line < 0) throw new Error(LINE_GTR_ZERO); - if (column < 0) throw new Error(COL_GTR_EQ_ZERO); - - const { sources, resolvedSources } = map; - let sourceIndex = sources.indexOf(source); - if (sourceIndex === -1) sourceIndex = resolvedSources.indexOf(source); - if (sourceIndex === -1) return all ? [] : GMapping(null, null); - - const generated = (map._bySources ||= buildBySources( - decodedMappings(map), - (map._bySourceMemos = sources.map(memoizedState)), - )); - - const segments = generated[sourceIndex][line]; - if (segments == null) return all ? [] : GMapping(null, null); - - const memo = map._bySourceMemos![sourceIndex]; - - if (all) return sliceGeneratedPositions(segments, memo, line, column, bias); - - const index = traceSegmentInternal(segments, memo, line, column, bias); - if (index === -1) return GMapping(null, null); - - const segment = segments[index]; - return GMapping(segment[REV_GENERATED_LINE] + 1, segment[REV_GENERATED_COLUMN]); - } - } +export function encodedMap(map: TraceMap): EncodedSourceMap { + return clone(map, encodedMappings(map)); } function clone( @@ -479,3 +422,55 @@ function sliceGeneratedPositions( } return result; } + +function generatedPosition( + map: TraceMap, + source: string, + line: number, + column: number, + bias: Bias, + all: false, +): GeneratedMapping | InvalidGeneratedMapping; +function generatedPosition( + map: TraceMap, + source: string, + line: number, + column: number, + bias: Bias, + all: true, +): GeneratedMapping[]; +function generatedPosition( + map: TraceMap, + source: string, + line: number, + column: number, + bias: Bias, + all: boolean, +): GeneratedMapping | InvalidGeneratedMapping | GeneratedMapping[] { + line--; + if (line < 0) throw new Error(LINE_GTR_ZERO); + if (column < 0) throw new Error(COL_GTR_EQ_ZERO); + + const { sources, resolvedSources } = map; + let sourceIndex = sources.indexOf(source); + if (sourceIndex === -1) sourceIndex = resolvedSources.indexOf(source); + if (sourceIndex === -1) return all ? [] : GMapping(null, null); + + const generated = (cast(map)._bySources ||= buildBySources( + decodedMappings(map), + (cast(map)._bySourceMemos = sources.map(memoizedState)), + )); + + const segments = generated[sourceIndex][line]; + if (segments == null) return all ? [] : GMapping(null, null); + + const memo = cast(map)._bySourceMemos![sourceIndex]; + + if (all) return sliceGeneratedPositions(segments, memo, line, column, bias); + + const index = traceSegmentInternal(segments, memo, line, column, bias); + if (index === -1) return GMapping(null, null); + + const segment = segments[index]; + return GMapping(segment[REV_GENERATED_LINE] + 1, segment[REV_GENERATED_COLUMN]); +} diff --git a/test/any-map.test.ts b/test/any-map.test.ts index a68a650..6185988 100644 --- a/test/any-map.test.ts +++ b/test/any-map.test.ts @@ -1,6 +1,6 @@ /// -import { test, describe } from './setup'; +import { strict as assert } from 'assert'; import { AnyMap, encodedMappings, decodedMappings } from '../src/trace-mapping'; import type { SectionedSourceMap, SourceMapSegment } from '../src/trace-mapping'; @@ -70,39 +70,39 @@ describe('AnyMap', () => { }; describe('map properties', () => { - test('version', (t) => { + it('version', () => { const tracer = new AnyMap(map); - t.is(tracer.version, map.version); + assert.equal(tracer.version, map.version); }); - test('file', (t) => { + it('file', () => { const tracer = new AnyMap(map); - t.is(tracer.file, map.file); + assert.equal(tracer.file, map.file); }); - test('sourceRoot', (t) => { + it('sourceRoot', () => { const tracer = new AnyMap(map); - t.is(tracer.sourceRoot, undefined); + assert.equal(tracer.sourceRoot, undefined); }); - test('sources', (t) => { + it('sources', () => { const tracer = new AnyMap(map); - t.deepEqual(tracer.sources, ['first.js', 'second.js', 'nested/third.js', 'fourth.js']); + assert.deepEqual(tracer.sources, ['first.js', 'second.js', 'nested/third.js', 'fourth.js']); }); - test('names', (t) => { + it('names', () => { const tracer = new AnyMap(map); - t.deepEqual(tracer.names, ['first', 'second', 'third']); + assert.deepEqual(tracer.names, ['first', 'second', 'third']); }); - test('encodedMappings', (t) => { + it('encodedMappings', () => { const tracer = new AnyMap(map); - t.is(encodedMappings(tracer), ';EAAAA,CCAAC;ACAAC,CCAA'); + assert.equal(encodedMappings(tracer), ';EAAAA,CCAAC;ACAAC,CCAA'); }); - test('decodedMappings', (t) => { + it('decodedMappings', () => { const tracer = new AnyMap(map); - t.deepEqual(decodedMappings(tracer), [ + assert.deepEqual(decodedMappings(tracer), [ [], [ [2, 0, 0, 0, 0], @@ -115,9 +115,9 @@ describe('AnyMap', () => { ]); }); - test('sourcesContent', (t) => { + it('sourcesContent', () => { const tracer = new AnyMap(map); - t.deepEqual(tracer.sourcesContent, [ + assert.deepEqual(tracer.sourcesContent, [ 'firstsource', 'secondsource', 'thirdsource', @@ -127,10 +127,8 @@ describe('AnyMap', () => { }); describe('typescript readonly type', () => { - test('decoded source map', (t) => { + it('decoded source map', () => { // This is a TS lint test, not a real one. - t.pass(); - const decodedMap = { version: 3 as const, sources: ['input.js'] as readonly string[], diff --git a/test/binary-search.test.ts b/test/binary-search.test.ts index 2555db6..ffaa1b4 100644 --- a/test/binary-search.test.ts +++ b/test/binary-search.test.ts @@ -1,378 +1,378 @@ +import { strict as assert } from 'assert'; import { binarySearch, found, memoizedState, memoizedBinarySearch } from '../src/binary-search'; -import { test, describe } from './setup'; type SourceMapSegment = [number]; describe('binary search', () => { - test('returns index of match', (t) => { + it('returns index of match', () => { const array: SourceMapSegment[] = []; array.push([0]); - t.is(binarySearch(array, 0, 0, array.length - 1), 0); + assert.equal(binarySearch(array, 0, 0, array.length - 1), 0); array.push([1]); - t.is(binarySearch(array, 0, 0, array.length - 1), 0); - t.is(binarySearch(array, 1, 0, array.length - 1), 1); + assert.equal(binarySearch(array, 0, 0, array.length - 1), 0); + assert.equal(binarySearch(array, 1, 0, array.length - 1), 1); array.push([2]); - t.is(binarySearch(array, 0, 0, array.length - 1), 0); - t.is(binarySearch(array, 1, 0, array.length - 1), 1); - t.is(binarySearch(array, 2, 0, array.length - 1), 2); + assert.equal(binarySearch(array, 0, 0, array.length - 1), 0); + assert.equal(binarySearch(array, 1, 0, array.length - 1), 1); + assert.equal(binarySearch(array, 2, 0, array.length - 1), 2); array.push([3]); - t.is(binarySearch(array, 0, 0, array.length - 1), 0); - t.is(binarySearch(array, 1, 0, array.length - 1), 1); - t.is(binarySearch(array, 2, 0, array.length - 1), 2); - t.is(binarySearch(array, 3, 0, array.length - 1), 3); + assert.equal(binarySearch(array, 0, 0, array.length - 1), 0); + assert.equal(binarySearch(array, 1, 0, array.length - 1), 1); + assert.equal(binarySearch(array, 2, 0, array.length - 1), 2); + assert.equal(binarySearch(array, 3, 0, array.length - 1), 3); array.push([4]); - t.is(binarySearch(array, 0, 0, array.length - 1), 0); - t.is(binarySearch(array, 1, 0, array.length - 1), 1); - t.is(binarySearch(array, 2, 0, array.length - 1), 2); - t.is(binarySearch(array, 3, 0, array.length - 1), 3); - t.is(binarySearch(array, 4, 0, array.length - 1), 4); + assert.equal(binarySearch(array, 0, 0, array.length - 1), 0); + assert.equal(binarySearch(array, 1, 0, array.length - 1), 1); + assert.equal(binarySearch(array, 2, 0, array.length - 1), 2); + assert.equal(binarySearch(array, 3, 0, array.length - 1), 3); + assert.equal(binarySearch(array, 4, 0, array.length - 1), 4); array.push([5]); - t.is(binarySearch(array, 0, 0, array.length - 1), 0); - t.is(binarySearch(array, 1, 0, array.length - 1), 1); - t.is(binarySearch(array, 2, 0, array.length - 1), 2); - t.is(binarySearch(array, 3, 0, array.length - 1), 3); - t.is(binarySearch(array, 4, 0, array.length - 1), 4); - t.is(binarySearch(array, 5, 0, array.length - 1), 5); + assert.equal(binarySearch(array, 0, 0, array.length - 1), 0); + assert.equal(binarySearch(array, 1, 0, array.length - 1), 1); + assert.equal(binarySearch(array, 2, 0, array.length - 1), 2); + assert.equal(binarySearch(array, 3, 0, array.length - 1), 3); + assert.equal(binarySearch(array, 4, 0, array.length - 1), 4); + assert.equal(binarySearch(array, 5, 0, array.length - 1), 5); }); - test('for non-match returns index for value lower than needle', (t) => { + it('for non-match returns index for value lower than needle', () => { // Test middles, which have a number left and right of index. const array: SourceMapSegment[] = []; array.push([0]); - t.is(binarySearch(array, -1, 0, array.length - 1), -1); - t.is(binarySearch(array, 1, 0, array.length - 1), 0); + assert.equal(binarySearch(array, -1, 0, array.length - 1), -1); + assert.equal(binarySearch(array, 1, 0, array.length - 1), 0); array.push([2]); - t.is(binarySearch(array, -1, 0, array.length - 1), -1); - t.is(binarySearch(array, 1, 0, array.length - 1), 0); - t.is(binarySearch(array, 3, 0, array.length - 1), 1); + assert.equal(binarySearch(array, -1, 0, array.length - 1), -1); + assert.equal(binarySearch(array, 1, 0, array.length - 1), 0); + assert.equal(binarySearch(array, 3, 0, array.length - 1), 1); array.push([4]); - t.is(binarySearch(array, -1, 0, array.length - 1), -1); - t.is(binarySearch(array, 1, 0, array.length - 1), 0); - t.is(binarySearch(array, 3, 0, array.length - 1), 1); - t.is(binarySearch(array, 5, 0, array.length - 1), 2); + assert.equal(binarySearch(array, -1, 0, array.length - 1), -1); + assert.equal(binarySearch(array, 1, 0, array.length - 1), 0); + assert.equal(binarySearch(array, 3, 0, array.length - 1), 1); + assert.equal(binarySearch(array, 5, 0, array.length - 1), 2); array.push([6]); - t.is(binarySearch(array, -1, 0, array.length - 1), -1); - t.is(binarySearch(array, 1, 0, array.length - 1), 0); - t.is(binarySearch(array, 3, 0, array.length - 1), 1); - t.is(binarySearch(array, 5, 0, array.length - 1), 2); - t.is(binarySearch(array, 7, 0, array.length - 1), 3); + assert.equal(binarySearch(array, -1, 0, array.length - 1), -1); + assert.equal(binarySearch(array, 1, 0, array.length - 1), 0); + assert.equal(binarySearch(array, 3, 0, array.length - 1), 1); + assert.equal(binarySearch(array, 5, 0, array.length - 1), 2); + assert.equal(binarySearch(array, 7, 0, array.length - 1), 3); array.push([8]); - t.is(binarySearch(array, -1, 0, array.length - 1), -1); - t.is(binarySearch(array, 1, 0, array.length - 1), 0); - t.is(binarySearch(array, 3, 0, array.length - 1), 1); - t.is(binarySearch(array, 5, 0, array.length - 1), 2); - t.is(binarySearch(array, 7, 0, array.length - 1), 3); - t.is(binarySearch(array, 9, 0, array.length - 1), 4); + assert.equal(binarySearch(array, -1, 0, array.length - 1), -1); + assert.equal(binarySearch(array, 1, 0, array.length - 1), 0); + assert.equal(binarySearch(array, 3, 0, array.length - 1), 1); + assert.equal(binarySearch(array, 5, 0, array.length - 1), 2); + assert.equal(binarySearch(array, 7, 0, array.length - 1), 3); + assert.equal(binarySearch(array, 9, 0, array.length - 1), 4); array.push([10]); - t.is(binarySearch(array, -1, 0, array.length - 1), -1); - t.is(binarySearch(array, 1, 0, array.length - 1), 0); - t.is(binarySearch(array, 3, 0, array.length - 1), 1); - t.is(binarySearch(array, 5, 0, array.length - 1), 2); - t.is(binarySearch(array, 7, 0, array.length - 1), 3); - t.is(binarySearch(array, 9, 0, array.length - 1), 4); - t.is(binarySearch(array, 11, 0, array.length - 1), 5); + assert.equal(binarySearch(array, -1, 0, array.length - 1), -1); + assert.equal(binarySearch(array, 1, 0, array.length - 1), 0); + assert.equal(binarySearch(array, 3, 0, array.length - 1), 1); + assert.equal(binarySearch(array, 5, 0, array.length - 1), 2); + assert.equal(binarySearch(array, 7, 0, array.length - 1), 3); + assert.equal(binarySearch(array, 9, 0, array.length - 1), 4); + assert.equal(binarySearch(array, 11, 0, array.length - 1), 5); }); - test('needle is lower than all elements returns -1', (t) => { + it('needle is lower than all elements returns -1', () => { const array: SourceMapSegment[] = []; const needle = -1; array.push([0]); - t.is(binarySearch(array, needle, 0, array.length - 1), -1); + assert.equal(binarySearch(array, needle, 0, array.length - 1), -1); array.push([1]); - t.is(binarySearch(array, needle, 0, array.length - 1), -1); + assert.equal(binarySearch(array, needle, 0, array.length - 1), -1); array.push([2]); - t.is(binarySearch(array, needle, 0, array.length - 1), -1); + assert.equal(binarySearch(array, needle, 0, array.length - 1), -1); array.push([3]); - t.is(binarySearch(array, needle, 0, array.length - 1), -1); + assert.equal(binarySearch(array, needle, 0, array.length - 1), -1); array.push([4]); - t.is(binarySearch(array, needle, 0, array.length - 1), -1); + assert.equal(binarySearch(array, needle, 0, array.length - 1), -1); array.push([5]); - t.is(binarySearch(array, needle, 0, array.length - 1), -1); + assert.equal(binarySearch(array, needle, 0, array.length - 1), -1); }); - test('needle is higher than all elements returns last index', (t) => { + it('needle is higher than all elements returns last index', () => { const array: SourceMapSegment[] = []; const needle = 2 ** 16; array.push([0]); - t.is(binarySearch(array, needle, 0, array.length - 1), array.length - 1); + assert.equal(binarySearch(array, needle, 0, array.length - 1), array.length - 1); array.push([1]); - t.is(binarySearch(array, needle, 0, array.length - 1), array.length - 1); + assert.equal(binarySearch(array, needle, 0, array.length - 1), array.length - 1); array.push([2]); - t.is(binarySearch(array, needle, 0, array.length - 1), array.length - 1); + assert.equal(binarySearch(array, needle, 0, array.length - 1), array.length - 1); array.push([3]); - t.is(binarySearch(array, needle, 0, array.length - 1), array.length - 1); + assert.equal(binarySearch(array, needle, 0, array.length - 1), array.length - 1); array.push([4]); - t.is(binarySearch(array, needle, 0, array.length - 1), array.length - 1); + assert.equal(binarySearch(array, needle, 0, array.length - 1), array.length - 1); array.push([5]); - t.is(binarySearch(array, needle, 0, array.length - 1), array.length - 1); + assert.equal(binarySearch(array, needle, 0, array.length - 1), array.length - 1); }); - test('empty array returns -1', (t) => { + it('empty array returns -1', () => { const array: SourceMapSegment[] = []; - t.is(binarySearch(array, -1, 0, array.length - 1), -1); - t.is(binarySearch(array, 0, 0, array.length - 1), -1); - t.is(binarySearch(array, 1, 0, array.length - 1), -1); + assert.equal(binarySearch(array, -1, 0, array.length - 1), -1); + assert.equal(binarySearch(array, 0, 0, array.length - 1), -1); + assert.equal(binarySearch(array, 1, 0, array.length - 1), -1); }); - test('multiple items in array returns any match', (t) => { + it('multiple items in array returns any match', () => { const array: SourceMapSegment[] = []; const needle = 1; array.push([needle]); - t.is(binarySearch(array, needle, 0, array.length - 1), 0); + assert.equal(binarySearch(array, needle, 0, array.length - 1), 0); array.push([needle]); - t.is(binarySearch(array, needle, 0, array.length - 1), 0); + assert.equal(binarySearch(array, needle, 0, array.length - 1), 0); array.push([needle]); - t.is(binarySearch(array, needle, 0, array.length - 1), 1); + assert.equal(binarySearch(array, needle, 0, array.length - 1), 1); array.push([needle]); - t.is(binarySearch(array, needle, 0, array.length - 1), 1); + assert.equal(binarySearch(array, needle, 0, array.length - 1), 1); array.push([needle]); - t.is(binarySearch(array, needle, 0, array.length - 1), 2); + assert.equal(binarySearch(array, needle, 0, array.length - 1), 2); array.push([needle]); - t.is(binarySearch(array, needle, 0, array.length - 1), 2); + assert.equal(binarySearch(array, needle, 0, array.length - 1), 2); }); describe('low', () => { - test('low equals needle index returns needle index', (t) => { + it('low equals needle index returns needle index', () => { const array: SourceMapSegment[] = []; array.push([0]); - t.is(binarySearch(array, 0, 0, array.length - 1), 0); + assert.equal(binarySearch(array, 0, 0, array.length - 1), 0); array.push([1]); - t.is(binarySearch(array, 0, 0, array.length - 1), 0); - t.is(binarySearch(array, 1, 1, array.length - 1), 1); + assert.equal(binarySearch(array, 0, 0, array.length - 1), 0); + assert.equal(binarySearch(array, 1, 1, array.length - 1), 1); array.push([2]); - t.is(binarySearch(array, 0, 0, array.length - 1), 0); - t.is(binarySearch(array, 1, 1, array.length - 1), 1); - t.is(binarySearch(array, 2, 2, array.length - 1), 2); + assert.equal(binarySearch(array, 0, 0, array.length - 1), 0); + assert.equal(binarySearch(array, 1, 1, array.length - 1), 1); + assert.equal(binarySearch(array, 2, 2, array.length - 1), 2); array.push([3]); - t.is(binarySearch(array, 0, 0, array.length - 1), 0); - t.is(binarySearch(array, 1, 1, array.length - 1), 1); - t.is(binarySearch(array, 2, 2, array.length - 1), 2); - t.is(binarySearch(array, 3, 3, array.length - 1), 3); + assert.equal(binarySearch(array, 0, 0, array.length - 1), 0); + assert.equal(binarySearch(array, 1, 1, array.length - 1), 1); + assert.equal(binarySearch(array, 2, 2, array.length - 1), 2); + assert.equal(binarySearch(array, 3, 3, array.length - 1), 3); array.push([4]); - t.is(binarySearch(array, 0, 0, array.length - 1), 0); - t.is(binarySearch(array, 1, 1, array.length - 1), 1); - t.is(binarySearch(array, 2, 2, array.length - 1), 2); - t.is(binarySearch(array, 3, 3, array.length - 1), 3); - t.is(binarySearch(array, 4, 4, array.length - 1), 4); + assert.equal(binarySearch(array, 0, 0, array.length - 1), 0); + assert.equal(binarySearch(array, 1, 1, array.length - 1), 1); + assert.equal(binarySearch(array, 2, 2, array.length - 1), 2); + assert.equal(binarySearch(array, 3, 3, array.length - 1), 3); + assert.equal(binarySearch(array, 4, 4, array.length - 1), 4); array.push([5]); - t.is(binarySearch(array, 0, 0, array.length - 1), 0); - t.is(binarySearch(array, 1, 1, array.length - 1), 1); - t.is(binarySearch(array, 2, 2, array.length - 1), 2); - t.is(binarySearch(array, 3, 3, array.length - 1), 3); - t.is(binarySearch(array, 4, 4, array.length - 1), 4); - t.is(binarySearch(array, 5, 5, array.length - 1), 5); + assert.equal(binarySearch(array, 0, 0, array.length - 1), 0); + assert.equal(binarySearch(array, 1, 1, array.length - 1), 1); + assert.equal(binarySearch(array, 2, 2, array.length - 1), 2); + assert.equal(binarySearch(array, 3, 3, array.length - 1), 3); + assert.equal(binarySearch(array, 4, 4, array.length - 1), 4); + assert.equal(binarySearch(array, 5, 5, array.length - 1), 5); }); - test('low higher than needle index returns left of high', (t) => { + it('low higher than needle index returns left of high', () => { const array: SourceMapSegment[] = []; array.push([0]); array.push([1]); - t.is(binarySearch(array, 0, 1, array.length - 1), 0); + assert.equal(binarySearch(array, 0, 1, array.length - 1), 0); array.push([2]); - t.is(binarySearch(array, 0, 1, array.length - 1), 0); - t.is(binarySearch(array, 0, 2, array.length - 1), 1); - t.is(binarySearch(array, 1, 2, array.length - 1), 1); + assert.equal(binarySearch(array, 0, 1, array.length - 1), 0); + assert.equal(binarySearch(array, 0, 2, array.length - 1), 1); + assert.equal(binarySearch(array, 1, 2, array.length - 1), 1); array.push([3]); - t.is(binarySearch(array, 0, 1, array.length - 1), 0); - t.is(binarySearch(array, 0, 2, array.length - 1), 1); - t.is(binarySearch(array, 0, 3, array.length - 1), 2); - t.is(binarySearch(array, 1, 2, array.length - 1), 1); - t.is(binarySearch(array, 1, 3, array.length - 1), 2); - t.is(binarySearch(array, 2, 3, array.length - 1), 2); + assert.equal(binarySearch(array, 0, 1, array.length - 1), 0); + assert.equal(binarySearch(array, 0, 2, array.length - 1), 1); + assert.equal(binarySearch(array, 0, 3, array.length - 1), 2); + assert.equal(binarySearch(array, 1, 2, array.length - 1), 1); + assert.equal(binarySearch(array, 1, 3, array.length - 1), 2); + assert.equal(binarySearch(array, 2, 3, array.length - 1), 2); array.push([4]); - t.is(binarySearch(array, 0, 1, array.length - 1), 0); - t.is(binarySearch(array, 0, 2, array.length - 1), 1); - t.is(binarySearch(array, 0, 3, array.length - 1), 2); - t.is(binarySearch(array, 0, 4, array.length - 1), 3); - t.is(binarySearch(array, 1, 2, array.length - 1), 1); - t.is(binarySearch(array, 1, 3, array.length - 1), 2); - t.is(binarySearch(array, 1, 4, array.length - 1), 3); - t.is(binarySearch(array, 2, 3, array.length - 1), 2); - t.is(binarySearch(array, 2, 4, array.length - 1), 3); - t.is(binarySearch(array, 3, 4, array.length - 1), 3); + assert.equal(binarySearch(array, 0, 1, array.length - 1), 0); + assert.equal(binarySearch(array, 0, 2, array.length - 1), 1); + assert.equal(binarySearch(array, 0, 3, array.length - 1), 2); + assert.equal(binarySearch(array, 0, 4, array.length - 1), 3); + assert.equal(binarySearch(array, 1, 2, array.length - 1), 1); + assert.equal(binarySearch(array, 1, 3, array.length - 1), 2); + assert.equal(binarySearch(array, 1, 4, array.length - 1), 3); + assert.equal(binarySearch(array, 2, 3, array.length - 1), 2); + assert.equal(binarySearch(array, 2, 4, array.length - 1), 3); + assert.equal(binarySearch(array, 3, 4, array.length - 1), 3); }); - test('low lower than needle index returns needle index', (t) => { + it('low lower than needle index returns needle index', () => { const array: SourceMapSegment[] = []; array.push([0]); array.push([1]); - t.is(binarySearch(array, 1, 0, array.length - 1), 1); + assert.equal(binarySearch(array, 1, 0, array.length - 1), 1); array.push([2]); - t.is(binarySearch(array, 1, 0, array.length - 1), 1); - t.is(binarySearch(array, 2, 0, array.length - 1), 2); - t.is(binarySearch(array, 2, 1, array.length - 1), 2); + assert.equal(binarySearch(array, 1, 0, array.length - 1), 1); + assert.equal(binarySearch(array, 2, 0, array.length - 1), 2); + assert.equal(binarySearch(array, 2, 1, array.length - 1), 2); array.push([3]); - t.is(binarySearch(array, 1, 0, array.length - 1), 1); - t.is(binarySearch(array, 2, 0, array.length - 1), 2); - t.is(binarySearch(array, 2, 1, array.length - 1), 2); - t.is(binarySearch(array, 3, 0, array.length - 1), 3); - t.is(binarySearch(array, 3, 1, array.length - 1), 3); - t.is(binarySearch(array, 3, 2, array.length - 1), 3); + assert.equal(binarySearch(array, 1, 0, array.length - 1), 1); + assert.equal(binarySearch(array, 2, 0, array.length - 1), 2); + assert.equal(binarySearch(array, 2, 1, array.length - 1), 2); + assert.equal(binarySearch(array, 3, 0, array.length - 1), 3); + assert.equal(binarySearch(array, 3, 1, array.length - 1), 3); + assert.equal(binarySearch(array, 3, 2, array.length - 1), 3); array.push([4]); - t.is(binarySearch(array, 1, 0, array.length - 1), 1); - t.is(binarySearch(array, 2, 0, array.length - 1), 2); - t.is(binarySearch(array, 2, 1, array.length - 1), 2); - t.is(binarySearch(array, 3, 0, array.length - 1), 3); - t.is(binarySearch(array, 3, 1, array.length - 1), 3); - t.is(binarySearch(array, 3, 2, array.length - 1), 3); - t.is(binarySearch(array, 4, 0, array.length - 1), 4); - t.is(binarySearch(array, 4, 1, array.length - 1), 4); - t.is(binarySearch(array, 4, 2, array.length - 1), 4); - t.is(binarySearch(array, 4, 3, array.length - 1), 4); + assert.equal(binarySearch(array, 1, 0, array.length - 1), 1); + assert.equal(binarySearch(array, 2, 0, array.length - 1), 2); + assert.equal(binarySearch(array, 2, 1, array.length - 1), 2); + assert.equal(binarySearch(array, 3, 0, array.length - 1), 3); + assert.equal(binarySearch(array, 3, 1, array.length - 1), 3); + assert.equal(binarySearch(array, 3, 2, array.length - 1), 3); + assert.equal(binarySearch(array, 4, 0, array.length - 1), 4); + assert.equal(binarySearch(array, 4, 1, array.length - 1), 4); + assert.equal(binarySearch(array, 4, 2, array.length - 1), 4); + assert.equal(binarySearch(array, 4, 3, array.length - 1), 4); }); }); describe('high', () => { - test('high equals needle index returns needle index', (t) => { + it('high equals needle index returns needle index', () => { const array: SourceMapSegment[] = []; array.push([0]); - t.is(binarySearch(array, 0, 0, 0), 0); + assert.equal(binarySearch(array, 0, 0, 0), 0); array.push([1]); - t.is(binarySearch(array, 0, 0, 0), 0); - t.is(binarySearch(array, 1, 0, 1), 1); + assert.equal(binarySearch(array, 0, 0, 0), 0); + assert.equal(binarySearch(array, 1, 0, 1), 1); array.push([2]); - t.is(binarySearch(array, 0, 0, 0), 0); - t.is(binarySearch(array, 1, 0, 1), 1); - t.is(binarySearch(array, 2, 0, 2), 2); + assert.equal(binarySearch(array, 0, 0, 0), 0); + assert.equal(binarySearch(array, 1, 0, 1), 1); + assert.equal(binarySearch(array, 2, 0, 2), 2); array.push([3]); - t.is(binarySearch(array, 0, 0, 0), 0); - t.is(binarySearch(array, 1, 0, 1), 1); - t.is(binarySearch(array, 2, 0, 2), 2); - t.is(binarySearch(array, 3, 0, 3), 3); + assert.equal(binarySearch(array, 0, 0, 0), 0); + assert.equal(binarySearch(array, 1, 0, 1), 1); + assert.equal(binarySearch(array, 2, 0, 2), 2); + assert.equal(binarySearch(array, 3, 0, 3), 3); array.push([4]); - t.is(binarySearch(array, 0, 0, 0), 0); - t.is(binarySearch(array, 1, 0, 1), 1); - t.is(binarySearch(array, 2, 0, 2), 2); - t.is(binarySearch(array, 3, 0, 3), 3); - t.is(binarySearch(array, 4, 0, 4), 4); + assert.equal(binarySearch(array, 0, 0, 0), 0); + assert.equal(binarySearch(array, 1, 0, 1), 1); + assert.equal(binarySearch(array, 2, 0, 2), 2); + assert.equal(binarySearch(array, 3, 0, 3), 3); + assert.equal(binarySearch(array, 4, 0, 4), 4); array.push([5]); - t.is(binarySearch(array, 0, 0, 0), 0); - t.is(binarySearch(array, 1, 0, 1), 1); - t.is(binarySearch(array, 2, 0, 2), 2); - t.is(binarySearch(array, 3, 0, 3), 3); - t.is(binarySearch(array, 4, 0, 4), 4); - t.is(binarySearch(array, 5, 0, 5), 5); + assert.equal(binarySearch(array, 0, 0, 0), 0); + assert.equal(binarySearch(array, 1, 0, 1), 1); + assert.equal(binarySearch(array, 2, 0, 2), 2); + assert.equal(binarySearch(array, 3, 0, 3), 3); + assert.equal(binarySearch(array, 4, 0, 4), 4); + assert.equal(binarySearch(array, 5, 0, 5), 5); }); - test('high higher than needle index returns needle index', (t) => { + it('high higher than needle index returns needle index', () => { const array: SourceMapSegment[] = []; array.push([0]); array.push([1]); - t.is(binarySearch(array, 0, 0, 1), 0); + assert.equal(binarySearch(array, 0, 0, 1), 0); array.push([2]); - t.is(binarySearch(array, 0, 0, 1), 0); - t.is(binarySearch(array, 0, 0, 2), 0); - t.is(binarySearch(array, 1, 0, 2), 1); + assert.equal(binarySearch(array, 0, 0, 1), 0); + assert.equal(binarySearch(array, 0, 0, 2), 0); + assert.equal(binarySearch(array, 1, 0, 2), 1); array.push([3]); - t.is(binarySearch(array, 0, 0, 1), 0); - t.is(binarySearch(array, 0, 0, 2), 0); - t.is(binarySearch(array, 0, 0, 3), 0); - t.is(binarySearch(array, 1, 0, 2), 1); - t.is(binarySearch(array, 1, 0, 3), 1); - t.is(binarySearch(array, 2, 0, 3), 2); + assert.equal(binarySearch(array, 0, 0, 1), 0); + assert.equal(binarySearch(array, 0, 0, 2), 0); + assert.equal(binarySearch(array, 0, 0, 3), 0); + assert.equal(binarySearch(array, 1, 0, 2), 1); + assert.equal(binarySearch(array, 1, 0, 3), 1); + assert.equal(binarySearch(array, 2, 0, 3), 2); array.push([4]); - t.is(binarySearch(array, 0, 0, 1), 0); - t.is(binarySearch(array, 0, 0, 2), 0); - t.is(binarySearch(array, 0, 0, 3), 0); - t.is(binarySearch(array, 0, 0, 4), 0); - t.is(binarySearch(array, 1, 0, 2), 1); - t.is(binarySearch(array, 1, 0, 3), 1); - t.is(binarySearch(array, 1, 0, 4), 1); - t.is(binarySearch(array, 2, 0, 3), 2); - t.is(binarySearch(array, 2, 0, 4), 2); - t.is(binarySearch(array, 3, 0, 4), 3); + assert.equal(binarySearch(array, 0, 0, 1), 0); + assert.equal(binarySearch(array, 0, 0, 2), 0); + assert.equal(binarySearch(array, 0, 0, 3), 0); + assert.equal(binarySearch(array, 0, 0, 4), 0); + assert.equal(binarySearch(array, 1, 0, 2), 1); + assert.equal(binarySearch(array, 1, 0, 3), 1); + assert.equal(binarySearch(array, 1, 0, 4), 1); + assert.equal(binarySearch(array, 2, 0, 3), 2); + assert.equal(binarySearch(array, 2, 0, 4), 2); + assert.equal(binarySearch(array, 3, 0, 4), 3); }); - test('high lower than needle index returns high', (t) => { + it('high lower than needle index returns high', () => { const array: SourceMapSegment[] = []; array.push([0]); array.push([1]); - t.is(binarySearch(array, 1, 0, 0), 0); + assert.equal(binarySearch(array, 1, 0, 0), 0); array.push([2]); - t.is(binarySearch(array, 1, 0, 0), 0); - t.is(binarySearch(array, 2, 0, 0), 0); - t.is(binarySearch(array, 2, 0, 1), 1); + assert.equal(binarySearch(array, 1, 0, 0), 0); + assert.equal(binarySearch(array, 2, 0, 0), 0); + assert.equal(binarySearch(array, 2, 0, 1), 1); array.push([3]); - t.is(binarySearch(array, 1, 0, 0), 0); - t.is(binarySearch(array, 2, 0, 0), 0); - t.is(binarySearch(array, 2, 0, 1), 1); - t.is(binarySearch(array, 3, 0, 0), 0); - t.is(binarySearch(array, 3, 0, 1), 1); - t.is(binarySearch(array, 3, 0, 2), 2); + assert.equal(binarySearch(array, 1, 0, 0), 0); + assert.equal(binarySearch(array, 2, 0, 0), 0); + assert.equal(binarySearch(array, 2, 0, 1), 1); + assert.equal(binarySearch(array, 3, 0, 0), 0); + assert.equal(binarySearch(array, 3, 0, 1), 1); + assert.equal(binarySearch(array, 3, 0, 2), 2); array.push([4]); - t.is(binarySearch(array, 1, 0, 0), 0); - t.is(binarySearch(array, 2, 0, 0), 0); - t.is(binarySearch(array, 2, 0, 1), 1); - t.is(binarySearch(array, 3, 0, 0), 0); - t.is(binarySearch(array, 3, 0, 1), 1); - t.is(binarySearch(array, 3, 0, 2), 2); - t.is(binarySearch(array, 4, 0, 0), 0); - t.is(binarySearch(array, 4, 0, 1), 1); - t.is(binarySearch(array, 4, 0, 2), 2); - t.is(binarySearch(array, 4, 0, 3), 3); + assert.equal(binarySearch(array, 1, 0, 0), 0); + assert.equal(binarySearch(array, 2, 0, 0), 0); + assert.equal(binarySearch(array, 2, 0, 1), 1); + assert.equal(binarySearch(array, 3, 0, 0), 0); + assert.equal(binarySearch(array, 3, 0, 1), 1); + assert.equal(binarySearch(array, 3, 0, 2), 2); + assert.equal(binarySearch(array, 4, 0, 0), 0); + assert.equal(binarySearch(array, 4, 0, 1), 1); + assert.equal(binarySearch(array, 4, 0, 2), 2); + assert.equal(binarySearch(array, 4, 0, 3), 3); }); }); }); @@ -380,27 +380,27 @@ describe('binary search', () => { describe('memoizedBinarySearch', () => { const array: SourceMapSegment[] = [[1], [5], [10]]; - test('refinds same index', (t) => { + it('refinds same index', () => { const memo = memoizedState(); - t.is(memoizedBinarySearch(array, 6, memo, 0), 1); - t.is(memoizedBinarySearch(array, 6, memo, 0), 1); + assert.equal(memoizedBinarySearch(array, 6, memo, 0), 1); + assert.equal(memoizedBinarySearch(array, 6, memo, 0), 1); }); - test('restores found state', (t) => { + it('restores found state', () => { const memo1 = memoizedState(); const memo2 = memoizedState(); - t.is(memoizedBinarySearch(array, 0, memo1, 0), -1); - t.is(found, false); + assert.equal(memoizedBinarySearch(array, 0, memo1, 0), -1); + assert.equal(found, false); - t.is(memoizedBinarySearch(array, 5, memo2, 0), 1); - t.is(found, true); + assert.equal(memoizedBinarySearch(array, 5, memo2, 0), 1); + assert.equal(found, true); - t.is(memoizedBinarySearch(array, 0, memo1, 0), -1); - t.is(found, false); + assert.equal(memoizedBinarySearch(array, 0, memo1, 0), -1); + assert.equal(found, false); - t.is(memoizedBinarySearch(array, 5, memo2, 0), 1); - t.is(found, true); + assert.equal(memoizedBinarySearch(array, 5, memo2, 0), 1); + assert.equal(found, true); }); }); diff --git a/test/resolve.test.ts b/test/resolve.test.ts index fcd4259..e1348e4 100644 --- a/test/resolve.test.ts +++ b/test/resolve.test.ts @@ -1,18 +1,18 @@ +import { strict as assert } from 'assert'; import resolve from '../src/resolve'; -import { test, describe } from './setup'; describe('resolve', () => { - test('resolves input relative to base', (t) => { + it('resolves input relative to base', () => { const base = 'bar/'; const input = 'foo'; - t.is(resolve(input, base), 'bar/foo'); + assert.equal(resolve(input, base), 'bar/foo'); }); - test('treats base as a directory regardless of slash', (t) => { + it('treats base as a directory regardless of slash', () => { const base = 'bar'; const input = 'foo'; - t.is(resolve(input, base), 'bar/foo'); + assert.equal(resolve(input, base), 'bar/foo'); }); }); diff --git a/test/setup.ts b/test/setup.ts deleted file mode 100644 index 8e0ddcd..0000000 --- a/test/setup.ts +++ /dev/null @@ -1,43 +0,0 @@ -import ava from 'ava'; -import type { Implementation } from 'ava'; - -const context: string[] = []; - -function describe(label: string, fn: () => void): void { - try { - context.push(label); - fn(); - } finally { - context.pop(); - } -} - -function getLabel(label: string): string { - context.push(label); - label = context.join(' - '); - context.pop(); - return label; -} - -// Copying type from node_modules/ava/types/test-fn.d.ts -const test = function test( - label: string, - fn: Implementation, - ...args: Args -): void { - ava(getLabel(label), fn, ...args); -}; - -test.macro = ava.macro; -test['only'] = (label: string, fn: Implementation, ...args: Args) => { - ava.only(getLabel(label), fn, ...args); -}; -test.skip = function skip( - label: string, - fn: Implementation, - ...args: Args -): void { - ava.skip(getLabel(label), fn, ...args); -}; - -export { test, describe, describe as context }; diff --git a/test/strip-filename.test.ts b/test/strip-filename.test.ts index d6a1140..d1b4c23 100644 --- a/test/strip-filename.test.ts +++ b/test/strip-filename.test.ts @@ -1,24 +1,24 @@ +import { strict as assert } from 'assert'; import stripFilename from '../src/strip-filename'; -import { test, describe } from './setup'; describe('stripFilename', () => { - test('returns empty string for empty string', (t) => { - t.is(stripFilename(''), ''); + it('returns empty string for empty string', () => { + assert.equal(stripFilename(''), ''); }); - test('returns empty string if no directory', (t) => { - t.is(stripFilename('foo'), ''); + it('returns empty string if no directory', () => { + assert.equal(stripFilename('foo'), ''); }); - test('it trims filename from directory path', (t) => { - t.is(stripFilename('/foo/bar/baz'), '/foo/bar/'); - t.is(stripFilename('/foo/bar'), '/foo/'); + it('it trims filename from directory path', () => { + assert.equal(stripFilename('/foo/bar/baz'), '/foo/bar/'); + assert.equal(stripFilename('/foo/bar'), '/foo/'); }); - test('it does nothing if trailing slash', (t) => { - t.is(stripFilename('/foo/bar/baz/'), '/foo/bar/baz/'); - t.is(stripFilename('/foo/bar/'), '/foo/bar/'); - t.is(stripFilename('/foo/'), '/foo/'); - t.is(stripFilename('/'), '/'); + it('it does nothing if trailing slash', () => { + assert.equal(stripFilename('/foo/bar/baz/'), '/foo/bar/baz/'); + assert.equal(stripFilename('/foo/bar/'), '/foo/bar/'); + assert.equal(stripFilename('/foo/'), '/foo/'); + assert.equal(stripFilename('/'), '/'); }); }); diff --git a/test/trace-mapping.test.ts b/test/trace-mapping.test.ts index 5a0a33c..0689403 100644 --- a/test/trace-mapping.test.ts +++ b/test/trace-mapping.test.ts @@ -1,8 +1,8 @@ /// +import { strict as assert } from 'assert'; import { encode, decode } from '@jridgewell/sourcemap-codec'; -import { test, describe } from './setup'; import { TraceMap, encodedMappings, @@ -18,7 +18,6 @@ import { allGeneratedPositionsFor, } from '../src/trace-mapping'; -import type { ExecutionContext } from 'ava'; import type { SourceMapInput, EncodedSourceMap, @@ -87,107 +86,107 @@ describe('TraceMap', () => { function testSuite(map: DecodedSourceMap | EncodedSourceMap | string) { return () => { describe('map properties', () => { - test('version', (t) => { + it('version', () => { const tracer = new TraceMap(map); - t.is(tracer.version, decodedMap.version); + assert.equal(tracer.version, decodedMap.version); }); - test('file', (t) => { + it('file', () => { const tracer = new TraceMap(map); - t.is(tracer.file, decodedMap.file); + assert.equal(tracer.file, decodedMap.file); }); - test('sourceRoot', (t) => { + it('sourceRoot', () => { const tracer = new TraceMap(map); - t.is(tracer.sourceRoot, decodedMap.sourceRoot); + assert.equal(tracer.sourceRoot, decodedMap.sourceRoot); }); - test('sources', (t) => { + it('sources', () => { const tracer = new TraceMap(map); - t.deepEqual(tracer.sources, decodedMap.sources); + assert.deepEqual(tracer.sources, decodedMap.sources); }); - test('names', (t) => { + it('names', () => { const tracer = new TraceMap(map); - t.deepEqual(tracer.names, decodedMap.names); + assert.deepEqual(tracer.names, decodedMap.names); }); - test('encodedMappings', (t) => { + it('encodedMappings', () => { const tracer = new TraceMap(map); - t.is(encodedMappings(tracer), encodedMap.mappings); + assert.equal(encodedMappings(tracer), encodedMap.mappings); }); - test('decodedMappings', (t) => { + it('decodedMappings', () => { const tracer = new TraceMap(map); - t.deepEqual(decodedMappings(tracer), decodedMap.mappings); + assert.deepEqual(decodedMappings(tracer), decodedMap.mappings); }); - test('sourcesContent', (t) => { + it('sourcesContent', () => { const tracer = new TraceMap(map); - t.deepEqual(tracer.sourcesContent, decodedMap.sourcesContent); + assert.deepEqual(tracer.sourcesContent, decodedMap.sourcesContent); }); describe('sourceContentFor', () => { - test('returns null if no sourcesContent', (t) => { + it('returns null if no sourcesContent', () => { const tracer = new TraceMap(replaceField(map, 'sourcesContent', undefined)); const source = tracer.sources[0]!; - t.is(sourceContentFor(tracer, source), null); + assert.equal(sourceContentFor(tracer, source), null); }); - test('returns null if source not found', (t) => { + it('returns null if source not found', () => { const tracer = new TraceMap(map); - t.is(sourceContentFor(tracer, 'foobar'), null); + assert.equal(sourceContentFor(tracer, 'foobar'), null); }); - test('returns sourceContent for source', (t) => { + it('returns sourceContent for source', () => { const tracer = new TraceMap(map); const source = tracer.sources[0]!; - t.is(sourceContentFor(tracer, source), decodedMap.sourcesContent![0]); + assert.equal(sourceContentFor(tracer, source), decodedMap.sourcesContent![0]); }); - test('returns sourceContent for resolved source', (t) => { + it('returns sourceContent for resolved source', () => { const tracer = new TraceMap(map); const source = tracer.resolvedSources[0]!; - t.is(sourceContentFor(tracer, source), decodedMap.sourcesContent![0]); + assert.equal(sourceContentFor(tracer, source), decodedMap.sourcesContent![0]); }); }); describe('resolvedSources', () => { - test('unresolved without sourceRoot', (t) => { + it('unresolved without sourceRoot', () => { const tracer = new TraceMap(replaceField(map, 'sourceRoot', undefined)); - t.deepEqual(tracer.resolvedSources, ['input.js']); + assert.deepEqual(tracer.resolvedSources, ['input.js']); }); - test('relative to mapUrl', (t) => { + it('relative to mapUrl', () => { const tracer = new TraceMap( replaceField(map, 'sourceRoot', undefined), 'foo/script.js.map', ); - t.deepEqual(tracer.resolvedSources, ['foo/input.js']); + assert.deepEqual(tracer.resolvedSources, ['foo/input.js']); }); - test('relative to sourceRoot', (t) => { + it('relative to sourceRoot', () => { const tracer = new TraceMap(replaceField(map, 'sourceRoot', 'foo')); - t.deepEqual(tracer.resolvedSources, ['foo/input.js']); + assert.deepEqual(tracer.resolvedSources, ['foo/input.js']); }); - test('relative to mapUrl then sourceRoot', (t) => { + it('relative to mapUrl then sourceRoot', () => { const tracer = new TraceMap( replaceField(map, 'sourceRoot', 'bar'), 'foo/script.js.map', ); - t.deepEqual(tracer.resolvedSources, ['foo/bar/input.js']); + assert.deepEqual(tracer.resolvedSources, ['foo/bar/input.js']); }); }); }); - test('traceSegment', (t) => { + it('traceSegment', () => { const { mappings } = decodedMap; const tracer = new TraceMap(map); // This comes before any segment on line 2, but importantly there are segments on line 1. If // binary searchign returns the last segment of line 1, we've failed. - t.is(traceSegment(tracer, 1, 0), null); + assert.equal(traceSegment(tracer, 1, 0), null); for (let line = 0; line < mappings.length; line++) { const segmentLine = mappings[line]; @@ -199,23 +198,23 @@ describe('TraceMap', () => { for (let column = segment[0]; column < nextColumn; column++) { const traced = traceSegment(tracer, line, column); - t.deepEqual(traced, segment, `{ line: ${line}, column: ${column} }`); + assert.deepEqual(traced, segment, `{ line: ${line}, column: ${column} }`); } } } }); - test('originalPositionFor', (t) => { + it('originalPositionFor', () => { const tracer = new TraceMap(map); - t.deepEqual(originalPositionFor(tracer, { line: 2, column: 13 }), { + assert.deepEqual(originalPositionFor(tracer, { line: 2, column: 13 }), { source: 'https://astexplorer.net/input.js', line: 2, column: 14, name: 'Error', }); - t.deepEqual( + assert.deepEqual( originalPositionFor(tracer, { line: 2, column: 13, bias: GREATEST_LOWER_BOUND }), { source: 'https://astexplorer.net/input.js', @@ -225,53 +224,62 @@ describe('TraceMap', () => { }, ); - t.deepEqual(originalPositionFor(tracer, { line: 2, column: 13, bias: LEAST_UPPER_BOUND }), { - source: 'https://astexplorer.net/input.js', - line: 2, - column: 10, - name: null, - }); + assert.deepEqual( + originalPositionFor(tracer, { line: 2, column: 13, bias: LEAST_UPPER_BOUND }), + { + source: 'https://astexplorer.net/input.js', + line: 2, + column: 10, + name: null, + }, + ); - t.deepEqual(originalPositionFor(tracer, { line: 100, column: 13 }), { + assert.deepEqual(originalPositionFor(tracer, { line: 100, column: 13 }), { source: null, line: null, column: null, name: null, }); - t.throws(() => { + assert.throws(() => { originalPositionFor(tracer, { line: 0, column: 13 }); }); - t.throws(() => { + assert.throws(() => { originalPositionFor(tracer, { line: 1, column: -1 }); }); }); - test('generatedPositionFor', (t) => { + it('generatedPositionFor', () => { const tracer = new TraceMap(map); - t.deepEqual(generatedPositionFor(tracer, { source: 'input.js', line: 4, column: 3 }), { + assert.deepEqual(generatedPositionFor(tracer, { source: 'input.js', line: 4, column: 3 }), { line: 5, column: 3, }); - t.deepEqual(generatedPositionFor(tracer, { source: 'input.js', line: 1, column: 0 }), { + assert.deepEqual(generatedPositionFor(tracer, { source: 'input.js', line: 1, column: 0 }), { line: 1, column: 0, }); - t.deepEqual(generatedPositionFor(tracer, { source: 'input.js', line: 1, column: 33 }), { - line: 1, - column: 18, - }); + assert.deepEqual( + generatedPositionFor(tracer, { source: 'input.js', line: 1, column: 33 }), + { + line: 1, + column: 18, + }, + ); - t.deepEqual(generatedPositionFor(tracer, { source: 'input.js', line: 1, column: 14 }), { - line: 1, - column: 13, - }); + assert.deepEqual( + generatedPositionFor(tracer, { source: 'input.js', line: 1, column: 14 }), + { + line: 1, + column: 13, + }, + ); - t.deepEqual( + assert.deepEqual( generatedPositionFor(tracer, { source: 'input.js', line: 1, @@ -284,7 +292,7 @@ describe('TraceMap', () => { }, ); - t.deepEqual( + assert.deepEqual( generatedPositionFor(tracer, { source: 'input.js', line: 1, @@ -297,16 +305,16 @@ describe('TraceMap', () => { }, ); - t.deepEqual(generatedPositionFor(tracer, { source: 'input.js', line: 4, column: 0 }), { + assert.deepEqual(generatedPositionFor(tracer, { source: 'input.js', line: 4, column: 0 }), { line: 5, column: 0, }); }); - test('allGeneratedPositionsFor', (t) => { + it('allGeneratedPositionsFor', () => { const tracer = new TraceMap(map); - t.deepEqual( + assert.deepEqual( allGeneratedPositionsFor(tracer, { source: 'input.js', line: 1, @@ -315,7 +323,7 @@ describe('TraceMap', () => { [{ line: 1, column: 18 }], ); - t.deepEqual( + assert.deepEqual( allGeneratedPositionsFor(tracer, { source: 'input.js', line: 2, @@ -328,7 +336,7 @@ describe('TraceMap', () => { ], ); - t.deepEqual( + assert.deepEqual( allGeneratedPositionsFor(tracer, { source: 'input.js', line: 2, @@ -342,7 +350,7 @@ describe('TraceMap', () => { ], ); - t.deepEqual( + assert.deepEqual( allGeneratedPositionsFor(tracer, { source: 'input.js', line: 2, @@ -355,7 +363,7 @@ describe('TraceMap', () => { ], ); - t.deepEqual( + assert.deepEqual( allGeneratedPositionsFor(tracer, { source: 'input.js', line: 2, @@ -368,7 +376,7 @@ describe('TraceMap', () => { ], ); - t.deepEqual( + assert.deepEqual( allGeneratedPositionsFor(tracer, { source: 'input.js', line: 2, @@ -382,19 +390,20 @@ describe('TraceMap', () => { ], ); - t.deepEqual( + assert.deepEqual( allGeneratedPositionsFor(tracer, { source: 'input.js', line: 100, column: 13 }), [], ); - t.deepEqual( + assert.deepEqual( allGeneratedPositionsFor(tracer, { source: 'input.js', line: 1, column: 100 }), [], ); - t.deepEqual(allGeneratedPositionsFor(tracer, { source: 'input.js', line: 1, column: 10 }), [ - { line: 1, column: 13 }, - ]); + assert.deepEqual( + allGeneratedPositionsFor(tracer, { source: 'input.js', line: 1, column: 10 }), + [{ line: 1, column: 13 }], + ); }); }; } @@ -416,15 +425,17 @@ describe('TraceMap', () => { ...encodedMap, mappings: encode(mappings), }; - const macro = test.macro((t: ExecutionContext, map: SourceMapInput) => { - const tracer = new TraceMap(map); - t.deepEqual(decodedMappings(tracer), decodedMap.mappings); - }); - test('decoded source map', macro, reversedDecoded); - test('json decoded source map', macro, JSON.stringify(reversedDecoded)); - test('encoded source map', macro, reversedEncoded); - test('json encoded source map', macro, JSON.stringify(reversedEncoded)); + function macro(map: SourceMapInput) { + return () => { + const tracer = new TraceMap(map); + assert.deepEqual(decodedMappings(tracer), decodedMap.mappings); + }; + } + it('decoded source map', macro(reversedDecoded)); + it('json decoded source map', macro(JSON.stringify(reversedDecoded))); + it('encoded source map', macro(reversedEncoded)); + it('json encoded source map', macro(JSON.stringify(reversedEncoded))); }); describe('empty mappings with lines', () => { @@ -437,17 +448,19 @@ describe('TraceMap', () => { mappings: ';;;;;;;;;;;;;;;;', }; - const macro = test.macro((t: ExecutionContext, map: SourceMapInput) => { - const tracer = new TraceMap(map); - for (let i = 0; i < decoded.mappings.length; i++) { - t.is(traceSegment(tracer, i, 0), null, `{ line: ${i} }`); - } - }); + function macro(map: SourceMapInput) { + return () => { + const tracer = new TraceMap(map); + for (let i = 0; i < decoded.mappings.length; i++) { + assert.equal(traceSegment(tracer, i, 0), null, `{ line: ${i} }`); + } + }; + } - test('decoded source map', macro, decoded); - test('json decoded source map', macro, JSON.stringify(decoded)); - test('encoded source map', macro, encoded); - test('json encoded source map', macro, JSON.stringify(encoded)); + it('decoded source map', macro(decoded)); + it('json decoded source map', macro(JSON.stringify(decoded))); + it('encoded source map', macro(encoded)); + it('json encoded source map', macro(JSON.stringify(encoded))); }); describe('eachMapping', () => { @@ -464,24 +477,24 @@ describe('TraceMap', () => { }); }); - const macro = test.macro((t: ExecutionContext, map: SourceMapInput) => { - t.plan(mappings.length); - - const tracer = new TraceMap(map); - let i = 0; - eachMapping(tracer, (mapping) => { - t.deepEqual(mapping, mappings[i++]); - }); - }); + function macro(map: SourceMapInput) { + return () => { + const tracer = new TraceMap(map); + let i = 0; + eachMapping(tracer, (mapping) => { + assert.deepEqual(mapping, mappings[i++]); + }); + }; + } - test('decoded source map', macro, decodedMap); - test('json decoded source map', macro, JSON.stringify(decodedMap)); - test('encoded source map', macro, encodedMap); - test('json encoded source map', macro, JSON.stringify(encodedMap)); + it('decoded source map', macro(decodedMap)); + it('json decoded source map', macro(JSON.stringify(decodedMap))); + it('encoded source map', macro(encodedMap)); + it('json encoded source map', macro(JSON.stringify(encodedMap))); }); describe('presortedDecodedMap', () => { - test('propagates decoded mappings without sorting', (t) => { + it('propagates decoded mappings without sorting', () => { const mappings = decodedMap.mappings.map((line) => { return line.slice().reverse(); }); @@ -491,10 +504,10 @@ describe('TraceMap', () => { }; const tracer = presortedDecodedMap(reversedDecoded); - t.deepEqual(decodedMappings(tracer), mappings); + assert.deepEqual(decodedMappings(tracer), mappings); }); - test('ignores non-sourcemap fields from output', (t) => { + it('ignores non-sourcemap fields from output', () => { // `map` will contain a `_encoded` field equal to the encoded map's, a _decoded equal to [], // and a _decodedMemo field. This fooled the duck-type early return detection, and preserved // invalid values on the presorted tracer. @@ -502,14 +515,13 @@ describe('TraceMap', () => { const map = Object.assign({}, new TraceMap(encodedMap), { mappings: [] }); const tracer = presortedDecodedMap(map); - t.is(encodedMappings(tracer), ''); + assert.equal(encodedMappings(tracer), ''); }); }); describe('typescript readonly type', () => { - test('decoded source map', (t) => { + it('decoded source map', () => { // This is a TS lint test, not a real one. - t.pass(); const decodedMap = { version: 3 as const,