示例工程 31-tsconfig-build-pipeline
31-tsconfig-build-pipeline/04-rootdir-sourcemap/main.test.mjs
点击「运行示例」后,左侧显示源码、右侧显示运行结果;console 输出会实时回传。
import { test } from 'node:test';
import assert from 'node:assert/strict';
import { existsSync, readFileSync } from 'node:fs';
import { fileURLToPath } from 'node:url';
import { dirname, join } from 'node:path';
import { run } from './dist/main.js';
const here = dirname(fileURLToPath(import.meta.url));
test('rootDir 决定产物布局,sourceMap 生成映射', () => {
const out = [];
assert.deepEqual(run((msg) => out.push(msg)), ['ok']);
assert.deepEqual(out, ['ok']);
assert.ok(existsSync(join(here, 'dist', 'main.js')), '产物在 dist 根下');
assert.ok(existsSync(join(here, 'dist', 'main.js.map')), '生成 source map');
assert.ok(readFileSync(join(here, 'dist', 'main.js'), 'utf8').includes('sourceMappingURL'), '产物引用 map');
});