mirror of
https://github.com/egoist/tsup.git
synced 2025-12-08 20:35:58 +00:00
test: replace ava with vitest
This commit is contained in:
parent
6aeb5ef746
commit
e6009846d0
12
package.json
12
package.json
@ -21,17 +21,9 @@
|
||||
"build": "tsup src/cli-*.ts src/index.ts src/rollup.ts --clean --splitting",
|
||||
"prepublishOnly": "npm run build",
|
||||
"test": "npm run build && npm run test-only",
|
||||
"test-only": "ava test/*.test.ts --fail-fast --timeout 60s",
|
||||
"test-only": "vitest run",
|
||||
"build-fast": "npm run build -- --no-dts"
|
||||
},
|
||||
"ava": {
|
||||
"extensions": [
|
||||
"ts"
|
||||
],
|
||||
"require": [
|
||||
"sucrase/register"
|
||||
]
|
||||
},
|
||||
"dependencies": {
|
||||
"bundle-require": "^3.0.2",
|
||||
"cac": "^6.7.12",
|
||||
@ -56,7 +48,6 @@
|
||||
"@types/fs-extra": "9.0.13",
|
||||
"@types/node": "14.18.4",
|
||||
"@types/resolve": "1.20.1",
|
||||
"ava": "4.0.0",
|
||||
"colorette": "2.0.16",
|
||||
"consola": "2.15.3",
|
||||
"flat": "5.0.2",
|
||||
@ -74,6 +65,7 @@
|
||||
"tsconfig-paths": "3.12.0",
|
||||
"tsup": "5.11.10",
|
||||
"typescript": "4.5.4",
|
||||
"vitest": "^0.2.5",
|
||||
"wait-for-expect": "3.0.2"
|
||||
},
|
||||
"peerDependencies": {
|
||||
|
||||
1019
pnpm-lock.yaml
generated
1019
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
311
test/__snapshots__/index.test.ts.snap
Normal file
311
test/__snapshots__/index.test.ts.snap
Normal file
@ -0,0 +1,311 @@
|
||||
// Vitest Snapshot v1
|
||||
|
||||
exports[`--env flag 1`] = `
|
||||
"var __defProp = Object.defineProperty;
|
||||
var __markAsModule = (target) => __defProp(target, \\"__esModule\\", { value: true });
|
||||
var __export = (target, all) => {
|
||||
__markAsModule(target);
|
||||
for (var name in all)
|
||||
__defProp(target, name, { get: all[name], enumerable: true });
|
||||
};
|
||||
|
||||
// input.ts
|
||||
__export(exports, {
|
||||
env: () => env
|
||||
});
|
||||
var env = \\"test\\";
|
||||
// Annotate the CommonJS export names for ESM import in node:
|
||||
0 && (module.exports = {
|
||||
env
|
||||
});
|
||||
"
|
||||
`;
|
||||
|
||||
exports[`bundle svelte 1`] = `
|
||||
"var __create = Object.create;
|
||||
var __defProp = Object.defineProperty;
|
||||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
||||
var __getOwnPropNames = Object.getOwnPropertyNames;
|
||||
var __getProtoOf = Object.getPrototypeOf;
|
||||
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
||||
var __markAsModule = (target) => __defProp(target, \\"__esModule\\", { value: true });
|
||||
var __export = (target, all) => {
|
||||
__markAsModule(target);
|
||||
for (var name in all)
|
||||
__defProp(target, name, { get: all[name], enumerable: true });
|
||||
};
|
||||
var __reExport = (target, module2, desc) => {
|
||||
if (module2 && typeof module2 === \\"object\\" || typeof module2 === \\"function\\") {
|
||||
for (let key of __getOwnPropNames(module2))
|
||||
if (!__hasOwnProp.call(target, key) && key !== \\"default\\")
|
||||
__defProp(target, key, { get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable });
|
||||
}
|
||||
return target;
|
||||
};
|
||||
var __toModule = (module2) => {
|
||||
return __reExport(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, \\"default\\", module2 && module2.__esModule && \\"default\\" in module2 ? { get: () => module2.default, enumerable: true } : { value: module2, enumerable: true })), module2);
|
||||
};
|
||||
|
||||
// input.ts
|
||||
__export(exports, {
|
||||
App: () => App_default
|
||||
});
|
||||
|
||||
// App.svelte
|
||||
var import_internal = __toModule(require(\\"svelte/internal\\"));
|
||||
function create_fragment(ctx) {
|
||||
let span;
|
||||
return {
|
||||
c() {
|
||||
span = (0, import_internal.element)(\\"span\\");
|
||||
span.textContent = \`\${msg}\`;
|
||||
(0, import_internal.attr)(span, \\"class\\", \\"svelte-1jo4k3z\\");
|
||||
},
|
||||
m(target, anchor) {
|
||||
(0, import_internal.insert)(target, span, anchor);
|
||||
},
|
||||
p: import_internal.noop,
|
||||
i: import_internal.noop,
|
||||
o: import_internal.noop,
|
||||
d(detaching) {
|
||||
if (detaching)
|
||||
(0, import_internal.detach)(span);
|
||||
}
|
||||
};
|
||||
}
|
||||
var msg = \\"hello svelte\\";
|
||||
var App = class extends import_internal.SvelteComponent {
|
||||
constructor(options) {
|
||||
super();
|
||||
(0, import_internal.init)(this, options, null, create_fragment, import_internal.safe_not_equal, {});
|
||||
}
|
||||
};
|
||||
var App_default = App;
|
||||
// Annotate the CommonJS export names for ESM import in node:
|
||||
0 && (module.exports = {
|
||||
App
|
||||
});
|
||||
"
|
||||
`;
|
||||
|
||||
exports[`bundle svelte 2`] = `
|
||||
"/* svelte-css:App.svelte.css */
|
||||
span.svelte-1jo4k3z {
|
||||
color: red;
|
||||
}
|
||||
"
|
||||
`;
|
||||
|
||||
exports[`code splitting in cjs format 1`] = `
|
||||
"\\"use strict\\";Object.defineProperty(exports, \\"__esModule\\", {value: true});
|
||||
|
||||
|
||||
var _chunk56VUBPK5js = require('./chunk-56VUBPK5.js');
|
||||
|
||||
// input.ts
|
||||
var foo = () => Promise.resolve().then(() => _chunk56VUBPK5js.__toModule.call(void 0, _chunk56VUBPK5js.__require.call(void 0, \\"./foo-UAUJLGDY.js\\")));
|
||||
|
||||
|
||||
exports.foo = foo;
|
||||
"
|
||||
`;
|
||||
|
||||
exports[`code splitting in cjs format 2`] = `
|
||||
"\\"use strict\\";Object.defineProperty(exports, \\"__esModule\\", {value: true});
|
||||
|
||||
|
||||
var _chunk56VUBPK5js = require('./chunk-56VUBPK5.js');
|
||||
|
||||
// another-input.ts
|
||||
var foo = () => Promise.resolve().then(() => _chunk56VUBPK5js.__toModule.call(void 0, _chunk56VUBPK5js.__require.call(void 0, \\"./foo-UAUJLGDY.js\\")));
|
||||
|
||||
|
||||
exports.foo = foo;
|
||||
"
|
||||
`;
|
||||
|
||||
exports[`declaration files with multiple entrypoints #316 1`] = `
|
||||
"declare const foo = 1;
|
||||
|
||||
export { foo };
|
||||
"
|
||||
`;
|
||||
|
||||
exports[`declaration files with multiple entrypoints #316 2`] = `
|
||||
"declare const bar = \\"bar\\";
|
||||
|
||||
export { bar };
|
||||
"
|
||||
`;
|
||||
|
||||
exports[`disable code splitting to get proper module.exports = 1`] = `
|
||||
"// input.ts
|
||||
module.exports = 123;
|
||||
"
|
||||
`;
|
||||
|
||||
exports[`enable --dts-resolve for specific module 1`] = `
|
||||
"export * from 'vue';
|
||||
|
||||
type MarkRequired<T, RK extends keyof T> = Exclude<T, RK> & Required<Pick<T, RK>>
|
||||
|
||||
export { MarkRequired };
|
||||
"
|
||||
`;
|
||||
|
||||
exports[`external 1`] = `
|
||||
"var __create = Object.create;
|
||||
var __defProp = Object.defineProperty;
|
||||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
||||
var __getOwnPropNames = Object.getOwnPropertyNames;
|
||||
var __getProtoOf = Object.getPrototypeOf;
|
||||
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
||||
var __markAsModule = (target) => __defProp(target, \\"__esModule\\", { value: true });
|
||||
var __export = (target, all) => {
|
||||
__markAsModule(target);
|
||||
for (var name in all)
|
||||
__defProp(target, name, { get: all[name], enumerable: true });
|
||||
};
|
||||
var __reExport = (target, module2, desc) => {
|
||||
if (module2 && typeof module2 === \\"object\\" || typeof module2 === \\"function\\") {
|
||||
for (let key of __getOwnPropNames(module2))
|
||||
if (!__hasOwnProp.call(target, key) && key !== \\"default\\")
|
||||
__defProp(target, key, { get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable });
|
||||
}
|
||||
return target;
|
||||
};
|
||||
var __toModule = (module2) => {
|
||||
return __reExport(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, \\"default\\", module2 && module2.__esModule && \\"default\\" in module2 ? { get: () => module2.default, enumerable: true } : { value: module2, enumerable: true })), module2);
|
||||
};
|
||||
|
||||
// input.ts
|
||||
__export(exports, {
|
||||
bar: () => import_bar.bar,
|
||||
baz: () => baz,
|
||||
foo: () => import_foo.foo
|
||||
});
|
||||
var import_foo = __toModule(require(\\"foo\\"));
|
||||
var import_bar = __toModule(require(\\"bar\\"));
|
||||
|
||||
// node_modules/baz/index.ts
|
||||
var baz = \\"baz\\";
|
||||
// Annotate the CommonJS export names for ESM import in node:
|
||||
0 && (module.exports = {
|
||||
bar,
|
||||
baz,
|
||||
foo
|
||||
});
|
||||
"
|
||||
`;
|
||||
|
||||
exports[`import css 1`] = `""`;
|
||||
|
||||
exports[`import css in --dts 1`] = `""`;
|
||||
|
||||
exports[`multiple targets 1`] = `
|
||||
"var __defProp = Object.defineProperty;
|
||||
var __markAsModule = (target) => __defProp(target, \\"__esModule\\", { value: true });
|
||||
var __export = (target, all) => {
|
||||
__markAsModule(target);
|
||||
for (var name in all)
|
||||
__defProp(target, name, { get: all[name], enumerable: true });
|
||||
};
|
||||
|
||||
// input.ts
|
||||
__export(exports, {
|
||||
answer: () => answer
|
||||
});
|
||||
var answer = 42;
|
||||
// Annotate the CommonJS export names for ESM import in node:
|
||||
0 && (module.exports = {
|
||||
answer
|
||||
});
|
||||
"
|
||||
`;
|
||||
|
||||
exports[`node protocol 1`] = `
|
||||
"var __create = Object.create;
|
||||
var __defProp = Object.defineProperty;
|
||||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
||||
var __getOwnPropNames = Object.getOwnPropertyNames;
|
||||
var __getProtoOf = Object.getPrototypeOf;
|
||||
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
||||
var __markAsModule = (target) => __defProp(target, \\"__esModule\\", { value: true });
|
||||
var __reExport = (target, module2, desc) => {
|
||||
if (module2 && typeof module2 === \\"object\\" || typeof module2 === \\"function\\") {
|
||||
for (let key of __getOwnPropNames(module2))
|
||||
if (!__hasOwnProp.call(target, key) && key !== \\"default\\")
|
||||
__defProp(target, key, { get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable });
|
||||
}
|
||||
return target;
|
||||
};
|
||||
var __toModule = (module2) => {
|
||||
return __reExport(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, \\"default\\", module2 && module2.__esModule && \\"default\\" in module2 ? { get: () => module2.default, enumerable: true } : { value: module2, enumerable: true })), module2);
|
||||
};
|
||||
|
||||
// input.ts
|
||||
var import_node_fs = __toModule(require(\\"fs\\"));
|
||||
console.log(import_node_fs.default);
|
||||
"
|
||||
`;
|
||||
|
||||
exports[`simple 1`] = `
|
||||
"var __defProp = Object.defineProperty;
|
||||
var __markAsModule = (target) => __defProp(target, \\"__esModule\\", { value: true });
|
||||
var __export = (target, all) => {
|
||||
__markAsModule(target);
|
||||
for (var name in all)
|
||||
__defProp(target, name, { get: all[name], enumerable: true });
|
||||
};
|
||||
|
||||
// input.ts
|
||||
__export(exports, {
|
||||
default: () => input_default
|
||||
});
|
||||
|
||||
// foo.ts
|
||||
var foo_default = \\"foo\\";
|
||||
|
||||
// input.ts
|
||||
var input_default = foo_default;
|
||||
// Annotate the CommonJS export names for ESM import in node:
|
||||
0 && (module.exports = {});
|
||||
"
|
||||
`;
|
||||
|
||||
exports[`support baseUrl and paths in tsconfig.json 1`] = `
|
||||
"var __defProp = Object.defineProperty;
|
||||
var __markAsModule = (target) => __defProp(target, \\"__esModule\\", { value: true });
|
||||
var __export = (target, all) => {
|
||||
__markAsModule(target);
|
||||
for (var name in all)
|
||||
__defProp(target, name, { get: all[name], enumerable: true });
|
||||
};
|
||||
|
||||
// input.ts
|
||||
__export(exports, {
|
||||
foo: () => foo
|
||||
});
|
||||
|
||||
// foo.ts
|
||||
var foo = \\"foo\\";
|
||||
// Annotate the CommonJS export names for ESM import in node:
|
||||
0 && (module.exports = {
|
||||
foo
|
||||
});
|
||||
"
|
||||
`;
|
||||
|
||||
exports[`support baseUrl and paths in tsconfig.json in --dts build 1`] = `
|
||||
"declare const foo = \\"foo\\";
|
||||
|
||||
export { foo };
|
||||
"
|
||||
`;
|
||||
|
||||
exports[`support baseUrl and paths in tsconfig.json in --dts-resolve build 1`] = `
|
||||
"declare const foo = \\"foo\\";
|
||||
|
||||
export { foo };
|
||||
"
|
||||
`;
|
||||
@ -1,15 +1,28 @@
|
||||
import test from 'ava'
|
||||
import { join, resolve } from 'path'
|
||||
import { test, expect, beforeAll } from 'vitest'
|
||||
import path from 'path'
|
||||
import execa from 'execa'
|
||||
import fs from 'fs-extra'
|
||||
import glob from 'globby'
|
||||
// import waitForExpect from 'wait-for-expect'
|
||||
// import { debouncePromise } from '../src/utils'
|
||||
import waitForExpect from 'wait-for-expect'
|
||||
import { fileURLToPath } from 'url'
|
||||
import { debouncePromise } from '../src/utils'
|
||||
|
||||
const cacheDir = resolve(__dirname, '.cache')
|
||||
const bin = resolve(__dirname, '../dist/cli-default.js')
|
||||
const __dirname = path.dirname(fileURLToPath(import.meta.url))
|
||||
|
||||
test.before(async () => {
|
||||
const cacheDir = path.resolve(__dirname, '.cache')
|
||||
const bin = path.resolve(__dirname, '../dist/cli-default.js')
|
||||
|
||||
const getTestName = () => {
|
||||
const name = expect.getState().currentTestName
|
||||
|
||||
if (!name) {
|
||||
throw new Error('No test name')
|
||||
}
|
||||
|
||||
return name
|
||||
}
|
||||
|
||||
beforeAll(async () => {
|
||||
await fs.remove(cacheDir)
|
||||
console.log(`Installing dependencies in ./test folder`)
|
||||
await execa('pnpm', ['i'], { cwd: __dirname })
|
||||
@ -29,12 +42,12 @@ async function run(
|
||||
env?: Record<string, string>
|
||||
} = {}
|
||||
) {
|
||||
const testDir = resolve(cacheDir, filenamify(title))
|
||||
const testDir = path.resolve(cacheDir, filenamify(title))
|
||||
|
||||
// Write entry files on disk
|
||||
await Promise.all(
|
||||
Object.keys(files).map((name) => {
|
||||
return fs.outputFile(resolve(testDir, name), files[name], 'utf8')
|
||||
return fs.outputFile(path.resolve(testDir, name), files[name], 'utf8')
|
||||
})
|
||||
)
|
||||
|
||||
@ -56,34 +69,34 @@ async function run(
|
||||
|
||||
// Get output
|
||||
const outFiles = await glob('**/*', {
|
||||
cwd: resolve(testDir, 'dist'),
|
||||
cwd: path.resolve(testDir, 'dist'),
|
||||
}).then((res) => res.sort())
|
||||
|
||||
return {
|
||||
get output() {
|
||||
return fs.readFileSync(resolve(testDir, 'dist/input.js'), 'utf8')
|
||||
return fs.readFileSync(path.resolve(testDir, 'dist/input.js'), 'utf8')
|
||||
},
|
||||
outFiles,
|
||||
logs,
|
||||
outDir: resolve(testDir, 'dist'),
|
||||
outDir: path.resolve(testDir, 'dist'),
|
||||
getFileContent(filename: string) {
|
||||
return fs.readFile(resolve(testDir, filename), 'utf8')
|
||||
return fs.readFile(path.resolve(testDir, filename), 'utf8')
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
test('simple', async (t) => {
|
||||
const { output, outFiles } = await run(t.title, {
|
||||
test('simple', async () => {
|
||||
const { output, outFiles } = await run(getTestName(), {
|
||||
'input.ts': `import foo from './foo';export default foo`,
|
||||
'foo.ts': `export default 'foo'`,
|
||||
})
|
||||
t.snapshot(output)
|
||||
t.deepEqual(outFiles, ['input.js'])
|
||||
expect(output).toMatchSnapshot()
|
||||
expect(outFiles).toEqual(['input.js'])
|
||||
})
|
||||
|
||||
test('bundle graphql-tools with --dts flag', async (t) => {
|
||||
test('bundle graphql-tools with --dts flag', async () => {
|
||||
await run(
|
||||
t.title,
|
||||
getTestName(),
|
||||
{
|
||||
'input.ts': `export { makeExecutableSchema } from 'graphql-tools'`,
|
||||
},
|
||||
@ -91,12 +104,11 @@ test('bundle graphql-tools with --dts flag', async (t) => {
|
||||
flags: ['--dts'],
|
||||
}
|
||||
)
|
||||
t.pass()
|
||||
})
|
||||
|
||||
test('bundle graphql-tools with --dts-resolve flag', async (t) => {
|
||||
test('bundle graphql-tools with --dts-resolve flag', async () => {
|
||||
await run(
|
||||
t.title,
|
||||
getTestName(),
|
||||
{
|
||||
'input.ts': `export { makeExecutableSchema } from 'graphql-tools'`,
|
||||
},
|
||||
@ -104,12 +116,11 @@ test('bundle graphql-tools with --dts-resolve flag', async (t) => {
|
||||
flags: ['--dts-resolve'],
|
||||
}
|
||||
)
|
||||
t.pass()
|
||||
})
|
||||
|
||||
test('bundle vue and ts-essentials with --dts --dts-resolve flag', async (t) => {
|
||||
test('bundle vue and ts-essentials with --dts --dts-resolve flag', async () => {
|
||||
await run(
|
||||
t.title,
|
||||
getTestName(),
|
||||
{
|
||||
'input.ts': `export * from 'vue'
|
||||
export type { MarkRequired } from 'ts-essentials'
|
||||
@ -119,12 +130,11 @@ test('bundle vue and ts-essentials with --dts --dts-resolve flag', async (t) =>
|
||||
flags: ['--dts', '--dts-resolve'],
|
||||
}
|
||||
)
|
||||
t.pass()
|
||||
})
|
||||
|
||||
test('bundle @egoist/path-parser with --dts --dts-resolve flag', async (t) => {
|
||||
test('bundle @egoist/path-parser with --dts --dts-resolve flag', async () => {
|
||||
const { getFileContent } = await run(
|
||||
t.title,
|
||||
getTestName(),
|
||||
{
|
||||
'input.ts': `import { PathParser } from '@egoist/path-parser'
|
||||
export type Opts = {
|
||||
@ -137,11 +147,10 @@ test('bundle @egoist/path-parser with --dts --dts-resolve flag', async (t) => {
|
||||
flags: ['--dts', '--dts-resolve'],
|
||||
}
|
||||
)
|
||||
t.pass()
|
||||
})
|
||||
|
||||
test('enable --dts-resolve for specific module', async (t) => {
|
||||
const { getFileContent } = await run(t.title, {
|
||||
test('enable --dts-resolve for specific module', async () => {
|
||||
const { getFileContent } = await run(getTestName(), {
|
||||
'input.ts': `export * from 'vue'
|
||||
export type {MarkRequired} from 'foo'
|
||||
`,
|
||||
@ -158,12 +167,12 @@ test('enable --dts-resolve for specific module', async (t) => {
|
||||
`,
|
||||
})
|
||||
const content = await getFileContent('dist/input.d.ts')
|
||||
t.snapshot(content)
|
||||
expect(content).toMatchSnapshot()
|
||||
})
|
||||
|
||||
test('bundle graphql-tools with --sourcemap flag', async (t) => {
|
||||
test('bundle graphql-tools with --sourcemap flag', async () => {
|
||||
const { outFiles } = await run(
|
||||
t.title,
|
||||
getTestName(),
|
||||
{
|
||||
'input.ts': `export { makeExecutableSchema } from 'graphql-tools'`,
|
||||
},
|
||||
@ -171,12 +180,12 @@ test('bundle graphql-tools with --sourcemap flag', async (t) => {
|
||||
flags: ['--sourcemap'],
|
||||
}
|
||||
)
|
||||
t.deepEqual(outFiles, ['input.js', 'input.js.map'])
|
||||
expect(outFiles).toEqual(['input.js', 'input.js.map'])
|
||||
})
|
||||
|
||||
test('bundle graphql-tools with --sourcemap inline flag', async (t) => {
|
||||
test('bundle graphql-tools with --sourcemap inline flag', async () => {
|
||||
const { output, outFiles } = await run(
|
||||
t.title,
|
||||
getTestName(),
|
||||
{
|
||||
'input.ts': `export { makeExecutableSchema } from 'graphql-tools'`,
|
||||
},
|
||||
@ -185,13 +194,13 @@ test('bundle graphql-tools with --sourcemap inline flag', async (t) => {
|
||||
}
|
||||
)
|
||||
|
||||
t.assert(output.includes('//# sourceMappingURL=data:application/json;base64'))
|
||||
t.deepEqual(outFiles, ['input.js'])
|
||||
expect(output).toContain('//# sourceMappingURL=data:application/json;base64')
|
||||
expect(outFiles).toEqual(['input.js'])
|
||||
})
|
||||
|
||||
test('multiple formats', async (t) => {
|
||||
test('multiple formats', async () => {
|
||||
const { output, outFiles } = await run(
|
||||
t.title,
|
||||
getTestName(),
|
||||
{
|
||||
'input.ts': `
|
||||
export const a = 1
|
||||
@ -202,13 +211,12 @@ test('multiple formats', async (t) => {
|
||||
}
|
||||
)
|
||||
|
||||
t.snapshot(output)
|
||||
t.deepEqual(outFiles, ['input.global.js', 'input.js', 'input.mjs'])
|
||||
expect(outFiles).toEqual(['input.global.js', 'input.js', 'input.mjs'])
|
||||
})
|
||||
|
||||
test('multiple formats and pkg.type is module', async (t) => {
|
||||
test('multiple formats and pkg.type is module', async () => {
|
||||
const { output, outFiles } = await run(
|
||||
t.title,
|
||||
getTestName(),
|
||||
{
|
||||
'input.ts': `
|
||||
export const a = 1
|
||||
@ -220,31 +228,12 @@ test('multiple formats and pkg.type is module', async (t) => {
|
||||
}
|
||||
)
|
||||
|
||||
t.snapshot(output)
|
||||
t.deepEqual(outFiles, ['input.cjs', 'input.global.js', 'input.js'])
|
||||
expect(outFiles).toEqual(['input.cjs', 'input.global.js', 'input.js'])
|
||||
})
|
||||
|
||||
test('multiple formats with legacy output', async (t) => {
|
||||
test('minify', async () => {
|
||||
const { output, outFiles } = await run(
|
||||
t.title,
|
||||
{
|
||||
'input.ts': `
|
||||
export const a = 1
|
||||
`,
|
||||
'package.json': JSON.stringify({ type: 'module' }),
|
||||
},
|
||||
{
|
||||
flags: ['--format', 'esm,cjs,iife', '--legacy-output'],
|
||||
}
|
||||
)
|
||||
|
||||
t.snapshot(output)
|
||||
t.deepEqual(outFiles, ['esm/input.js', 'iife/input.js', 'input.js'])
|
||||
})
|
||||
|
||||
test('minify', async (t) => {
|
||||
const { output, outFiles } = await run(
|
||||
t.title,
|
||||
getTestName(),
|
||||
{
|
||||
'input.ts': `
|
||||
export function foo() {
|
||||
@ -257,13 +246,13 @@ test('minify', async (t) => {
|
||||
}
|
||||
)
|
||||
|
||||
t.snapshot(output)
|
||||
t.deepEqual(outFiles, ['input.js'])
|
||||
expect(output).toContain(`return"foo"`)
|
||||
expect(outFiles).toEqual(['input.js'])
|
||||
})
|
||||
|
||||
test('--env flag', async (t) => {
|
||||
test('--env flag', async () => {
|
||||
const { output, outFiles } = await run(
|
||||
t.title,
|
||||
getTestName(),
|
||||
{
|
||||
'input.ts': `
|
||||
export const env = process.env.NODE_ENV
|
||||
@ -274,12 +263,12 @@ test('--env flag', async (t) => {
|
||||
}
|
||||
)
|
||||
|
||||
t.snapshot(output)
|
||||
t.deepEqual(outFiles, ['input.js'])
|
||||
expect(output).toMatchSnapshot()
|
||||
expect(outFiles).toEqual(['input.js'])
|
||||
})
|
||||
|
||||
test('import css', async (t) => {
|
||||
const { output, outFiles } = await run(t.title, {
|
||||
test('import css', async () => {
|
||||
const { output, outFiles } = await run(getTestName(), {
|
||||
'input.ts': `
|
||||
import './foo.css'
|
||||
`,
|
||||
@ -297,13 +286,13 @@ test('import css', async (t) => {
|
||||
`,
|
||||
})
|
||||
|
||||
t.snapshot(output, `""`)
|
||||
t.deepEqual(outFiles, ['input.css', 'input.js'])
|
||||
expect(output, `""`).toMatchSnapshot()
|
||||
expect(outFiles).toEqual(['input.css', 'input.js'])
|
||||
})
|
||||
|
||||
test('import css in --dts', async (t) => {
|
||||
test('import css in --dts', async () => {
|
||||
const { output, outFiles } = await run(
|
||||
t.title,
|
||||
getTestName(),
|
||||
{
|
||||
'input.ts': `
|
||||
import './foo.css'
|
||||
@ -317,19 +306,19 @@ test('import css in --dts', async (t) => {
|
||||
{ flags: ['--dts'] }
|
||||
)
|
||||
|
||||
t.snapshot(output)
|
||||
t.deepEqual(outFiles, ['input.css', 'input.d.ts', 'input.js'])
|
||||
expect(output).toMatchSnapshot()
|
||||
expect(outFiles).toEqual(['input.css', 'input.d.ts', 'input.js'])
|
||||
})
|
||||
|
||||
test('node protocol', async (t) => {
|
||||
const { output } = await run(t.title, {
|
||||
test('node protocol', async () => {
|
||||
const { output } = await run(getTestName(), {
|
||||
'input.ts': `import fs from 'node:fs'; console.log(fs)`,
|
||||
})
|
||||
t.snapshot(output)
|
||||
expect(output).toMatchSnapshot()
|
||||
})
|
||||
|
||||
test('external', async (t) => {
|
||||
const { output } = await run(t.title, {
|
||||
test('external', async () => {
|
||||
const { output } = await run(getTestName(), {
|
||||
'input.ts': `export {foo} from 'foo'
|
||||
export {bar} from 'bar'
|
||||
export {baz} from 'baz'
|
||||
@ -346,12 +335,12 @@ test('external', async (t) => {
|
||||
}
|
||||
`,
|
||||
})
|
||||
t.snapshot(output)
|
||||
expect(output).toMatchSnapshot()
|
||||
})
|
||||
|
||||
test('disable code splitting to get proper module.exports =', async (t) => {
|
||||
test('disable code splitting to get proper module.exports =', async () => {
|
||||
const { output } = await run(
|
||||
t.title,
|
||||
getTestName(),
|
||||
{
|
||||
'input.ts': `export = 123`,
|
||||
},
|
||||
@ -359,12 +348,12 @@ test('disable code splitting to get proper module.exports =', async (t) => {
|
||||
flags: ['--no-splitting'],
|
||||
}
|
||||
)
|
||||
t.snapshot(output)
|
||||
expect(output).toMatchSnapshot()
|
||||
})
|
||||
|
||||
test('bundle svelte', async (t) => {
|
||||
test('bundle svelte', async () => {
|
||||
const { output, getFileContent } = await run(
|
||||
t.title,
|
||||
getTestName(),
|
||||
{
|
||||
'input.ts': `import App from './App.svelte'
|
||||
export { App }
|
||||
@ -386,13 +375,13 @@ test('bundle svelte', async (t) => {
|
||||
flags: ['--external', 'svelte/internal'],
|
||||
}
|
||||
)
|
||||
t.snapshot(output, 'output')
|
||||
expect(output, 'output').toMatchSnapshot()
|
||||
|
||||
t.snapshot(await getFileContent('dist/input.css'), 'css')
|
||||
expect(await getFileContent('dist/input.css'), 'css').toMatchSnapshot()
|
||||
})
|
||||
|
||||
test('bundle svelte without styles', async (t) => {
|
||||
const { outFiles } = await run(t.title, {
|
||||
test('bundle svelte without styles', async () => {
|
||||
const { outFiles } = await run(getTestName(), {
|
||||
'input.ts': `import App from './App.svelte'
|
||||
export { App }
|
||||
`,
|
||||
@ -405,11 +394,11 @@ test('bundle svelte without styles', async (t) => {
|
||||
`,
|
||||
})
|
||||
|
||||
t.deepEqual(outFiles, ['input.js'])
|
||||
expect(outFiles).toEqual(['input.js'])
|
||||
})
|
||||
|
||||
test('svelte: typescript support', async (t) => {
|
||||
const { outFiles, output } = await run(t.title, {
|
||||
test('svelte: typescript support', async () => {
|
||||
const { outFiles, output } = await run(getTestName(), {
|
||||
'input.ts': `import App from './App.svelte'
|
||||
export { App }
|
||||
`,
|
||||
@ -431,14 +420,14 @@ test('svelte: typescript support', async (t) => {
|
||||
`,
|
||||
})
|
||||
|
||||
t.deepEqual(outFiles, ['input.js'])
|
||||
t.assert(output.includes('// Component.svelte'))
|
||||
expect(outFiles).toEqual(['input.js'])
|
||||
expect(output).toContain('// Component.svelte')
|
||||
})
|
||||
|
||||
test('onSuccess', async (t) => {
|
||||
test('onSuccess', async () => {
|
||||
const randomNumber = Math.random() + ''
|
||||
const { logs } = await run(
|
||||
t.title,
|
||||
getTestName(),
|
||||
{
|
||||
'input.ts': "console.log('test');",
|
||||
},
|
||||
@ -447,11 +436,11 @@ test('onSuccess', async (t) => {
|
||||
}
|
||||
)
|
||||
|
||||
t.deepEqual(logs.includes(randomNumber), true)
|
||||
expect(logs.includes(randomNumber)).toEqual(true)
|
||||
})
|
||||
|
||||
test('support baseUrl and paths in tsconfig.json', async (t) => {
|
||||
const { getFileContent } = await run(t.title, {
|
||||
test('support baseUrl and paths in tsconfig.json', async () => {
|
||||
const { getFileContent } = await run(getTestName(), {
|
||||
'input.ts': `export * from '@/foo'`,
|
||||
'foo.ts': `export const foo = 'foo'`,
|
||||
'tsconfig.json': `{
|
||||
@ -461,12 +450,12 @@ test('support baseUrl and paths in tsconfig.json', async (t) => {
|
||||
}
|
||||
}`,
|
||||
})
|
||||
t.snapshot(await getFileContent('dist/input.js'))
|
||||
expect(await getFileContent('dist/input.js')).toMatchSnapshot()
|
||||
})
|
||||
|
||||
test('support baseUrl and paths in tsconfig.json in --dts build', async (t) => {
|
||||
test('support baseUrl and paths in tsconfig.json in --dts build', async () => {
|
||||
const { getFileContent } = await run(
|
||||
t.title,
|
||||
getTestName(),
|
||||
{
|
||||
'input.ts': `export * from '@/foo'`,
|
||||
'src/foo.ts': `export const foo = 'foo'`,
|
||||
@ -479,12 +468,12 @@ test('support baseUrl and paths in tsconfig.json in --dts build', async (t) => {
|
||||
},
|
||||
{ flags: ['--dts'] }
|
||||
)
|
||||
t.snapshot(await getFileContent('dist/input.d.ts'))
|
||||
expect(await getFileContent('dist/input.d.ts')).toMatchSnapshot()
|
||||
})
|
||||
|
||||
test('support baseUrl and paths in tsconfig.json in --dts-resolve build', async (t) => {
|
||||
test('support baseUrl and paths in tsconfig.json in --dts-resolve build', async () => {
|
||||
const { getFileContent } = await run(
|
||||
t.title,
|
||||
getTestName(),
|
||||
{
|
||||
'input.ts': `export * from '@/foo'`,
|
||||
'src/foo.ts': `export const foo = 'foo'`,
|
||||
@ -497,19 +486,23 @@ test('support baseUrl and paths in tsconfig.json in --dts-resolve build', async
|
||||
},
|
||||
{ flags: ['--dts-resolve'] }
|
||||
)
|
||||
t.snapshot(await getFileContent('dist/input.d.ts'))
|
||||
expect(await getFileContent('dist/input.d.ts')).toMatchSnapshot()
|
||||
})
|
||||
|
||||
test(`transform import.meta.url in cjs format`, async (t) => {
|
||||
const { getFileContent } = await run(t.title, {
|
||||
'input.ts': `export default import.meta.url`,
|
||||
})
|
||||
t.snapshot(await getFileContent('dist/input.js'))
|
||||
})
|
||||
|
||||
test(`transform __dirname, __filename in esm format`, async (t) => {
|
||||
test(`transform import.meta.url in cjs format`, async () => {
|
||||
const { getFileContent } = await run(
|
||||
t.title,
|
||||
getTestName(),
|
||||
{
|
||||
'input.ts': `export default import.meta.url`,
|
||||
},
|
||||
{}
|
||||
)
|
||||
expect(await getFileContent('dist/input.js')).toContain('getImportMetaUrl')
|
||||
})
|
||||
|
||||
test(`transform __dirname and __filename in esm format`, async () => {
|
||||
const { getFileContent } = await run(
|
||||
getTestName(),
|
||||
{
|
||||
'input.ts': `export const a = __dirname
|
||||
export const b = __filename
|
||||
@ -519,71 +512,74 @@ test(`transform __dirname, __filename in esm format`, async (t) => {
|
||||
flags: ['--format', 'esm'],
|
||||
}
|
||||
)
|
||||
t.snapshot(await getFileContent('dist/input.mjs'))
|
||||
const code = await getFileContent('dist/input.mjs')
|
||||
|
||||
expect(code).toContain('getFilename')
|
||||
expect(code).toContain('getDirname')
|
||||
})
|
||||
|
||||
// test('debounce promise', async (t) => {
|
||||
// try {
|
||||
// const equal = <T>(a: T, b: T) => {
|
||||
// const result = a === b
|
||||
// if (!result) throw new Error(`${a} !== ${b}`)
|
||||
// }
|
||||
test('debounce promise', async () => {
|
||||
try {
|
||||
const equal = <T>(a: T, b: T) => {
|
||||
const result = a === b
|
||||
if (!result) throw new Error(`${a} !== ${b}`)
|
||||
}
|
||||
|
||||
// const sleep = (n: number = ~~(Math.random() * 50) + 20) =>
|
||||
// new Promise<void>((resolve) => setTimeout(resolve, n))
|
||||
const sleep = (n: number = ~~(Math.random() * 50) + 20) =>
|
||||
new Promise<void>((resolve) => setTimeout(resolve, n))
|
||||
|
||||
// let n = 0
|
||||
let n = 0
|
||||
|
||||
// const debounceFunction = debouncePromise(
|
||||
// async () => {
|
||||
// await sleep()
|
||||
// ++n
|
||||
// },
|
||||
// 100,
|
||||
// (err: any) => {
|
||||
// t.fail(err)
|
||||
// }
|
||||
// )
|
||||
const debounceFunction = debouncePromise(
|
||||
async () => {
|
||||
await sleep()
|
||||
++n
|
||||
},
|
||||
100,
|
||||
(err: any) => {
|
||||
expect.fail(err.message)
|
||||
}
|
||||
)
|
||||
|
||||
// t.deepEqual(n, 0)
|
||||
expect(n).toEqual(0)
|
||||
|
||||
// debounceFunction()
|
||||
// debounceFunction()
|
||||
// debounceFunction()
|
||||
// debounceFunction()
|
||||
debounceFunction()
|
||||
debounceFunction()
|
||||
debounceFunction()
|
||||
debounceFunction()
|
||||
|
||||
// await waitForExpect(() => {
|
||||
// equal(n, 1)
|
||||
// })
|
||||
// await sleep(100)
|
||||
await waitForExpect(() => {
|
||||
equal(n, 1)
|
||||
})
|
||||
await sleep(100)
|
||||
|
||||
// t.deepEqual(n, 1)
|
||||
expect(n).toEqual(1)
|
||||
|
||||
// debounceFunction()
|
||||
debounceFunction()
|
||||
|
||||
// await waitForExpect(() => {
|
||||
// equal(n, 2)
|
||||
// })
|
||||
// } catch (err: any) {
|
||||
// return t.fail(err)
|
||||
// }
|
||||
// })
|
||||
await waitForExpect(() => {
|
||||
equal(n, 2)
|
||||
})
|
||||
} catch (err: any) {
|
||||
return expect.fail(err.message)
|
||||
}
|
||||
})
|
||||
|
||||
test('exclude dependencies', async (t) => {
|
||||
const { getFileContent } = await run(t.title, {
|
||||
test('exclude dependencies', async () => {
|
||||
const { getFileContent } = await run(getTestName(), {
|
||||
'input.ts': `export {foo} from 'foo';export {nested} from 'foo/nested'`,
|
||||
'package.json': `{"dependencies":{"foo":"0.0.0"}}`,
|
||||
'node_modules/foo/index.js': `export const foo = 'foo'`,
|
||||
'node_modules/foo/package.json': `{"name":"foo"}`,
|
||||
})
|
||||
const contents = await getFileContent('dist/input.js')
|
||||
t.assert(contents.includes('require("foo")'))
|
||||
t.assert(contents.includes('require("foo/nested")'))
|
||||
expect(contents).toContain('require("foo")')
|
||||
expect(contents).toContain('require("foo/nested")')
|
||||
})
|
||||
|
||||
test('code splitting in cjs format', async (t) => {
|
||||
test('code splitting in cjs format', async () => {
|
||||
const { getFileContent } = await run(
|
||||
t.title,
|
||||
getTestName(),
|
||||
{
|
||||
'input.ts': `const foo = () => import('./foo');export {foo}`,
|
||||
'another-input.ts': `const foo = () => import('./foo');export {foo}`,
|
||||
@ -591,37 +587,43 @@ test('code splitting in cjs format', async (t) => {
|
||||
},
|
||||
{ flags: ['another-input.ts', '--splitting'] }
|
||||
)
|
||||
t.snapshot(await getFileContent('dist/input.js'))
|
||||
t.snapshot(await getFileContent('dist/another-input.js'))
|
||||
expect(await getFileContent('dist/input.js')).toMatchSnapshot()
|
||||
expect(await getFileContent('dist/another-input.js')).toMatchSnapshot()
|
||||
})
|
||||
|
||||
test('declaration files with multiple entrypoints #316', async (t) => {
|
||||
test('declaration files with multiple entrypoints #316', async () => {
|
||||
const { getFileContent } = await run(
|
||||
t.title,
|
||||
getTestName(),
|
||||
{
|
||||
'src/index.ts': `export const foo = 1`,
|
||||
'src/bar/index.ts': `export const bar = 'bar'`,
|
||||
},
|
||||
{ flags: ['--dts'], entry: ['src/index.ts', 'src/bar/index.ts'] }
|
||||
)
|
||||
t.snapshot(await getFileContent('dist/index.d.ts'), 'dist/index.d.ts')
|
||||
t.snapshot(await getFileContent('dist/bar/index.d.ts'), 'dist/bar/index.d.ts')
|
||||
expect(
|
||||
await getFileContent('dist/index.d.ts'),
|
||||
'dist/index.d.ts'
|
||||
).toMatchSnapshot()
|
||||
expect(
|
||||
await getFileContent('dist/bar/index.d.ts'),
|
||||
'dist/bar/index.d.ts'
|
||||
).toMatchSnapshot()
|
||||
})
|
||||
|
||||
test('esbuild metafile', async (t) => {
|
||||
test('esbuild metafile', async () => {
|
||||
const { outFiles } = await run(
|
||||
t.title,
|
||||
getTestName(),
|
||||
{ 'input.ts': `export const foo = 1` },
|
||||
{
|
||||
flags: ['--metafile'],
|
||||
}
|
||||
)
|
||||
t.deepEqual(outFiles, ['input.js', 'metafile-cjs.json'])
|
||||
expect(outFiles).toEqual(['input.js', 'metafile-cjs.json'])
|
||||
})
|
||||
|
||||
test('multiple entry with the same base name', async (t) => {
|
||||
test('multiple entry with the same base name', async () => {
|
||||
const { outFiles } = await run(
|
||||
t.title,
|
||||
getTestName(),
|
||||
{
|
||||
'src/input.ts': `export const foo = 1`,
|
||||
'src/bar/input.ts': `export const bar = 2`,
|
||||
@ -630,23 +632,23 @@ test('multiple entry with the same base name', async (t) => {
|
||||
entry: ['src/input.ts', 'src/bar/input.ts'],
|
||||
}
|
||||
)
|
||||
t.deepEqual(outFiles, ['bar/input.js', 'input.js'])
|
||||
expect(outFiles).toEqual(['bar/input.js', 'input.js'])
|
||||
})
|
||||
|
||||
test('windows: backslash in entry', async (t) => {
|
||||
test('windows: backslash in entry', async () => {
|
||||
const { outFiles } = await run(
|
||||
t.title,
|
||||
getTestName(),
|
||||
{ 'src/input.ts': `export const foo = 1` },
|
||||
{
|
||||
entry: ['src\\input.ts'],
|
||||
}
|
||||
)
|
||||
t.deepEqual(outFiles, ['input.js'])
|
||||
expect(outFiles).toEqual(['input.js'])
|
||||
})
|
||||
|
||||
test('emit declaration files only', async (t) => {
|
||||
test('emit declaration files only', async () => {
|
||||
const { outFiles } = await run(
|
||||
t.title,
|
||||
getTestName(),
|
||||
{
|
||||
'input.ts': `export const foo = 1`,
|
||||
},
|
||||
@ -654,11 +656,11 @@ test('emit declaration files only', async (t) => {
|
||||
flags: ['--dts-only'],
|
||||
}
|
||||
)
|
||||
t.deepEqual(outFiles, ['input.d.ts'])
|
||||
expect(outFiles).toEqual(['input.d.ts'])
|
||||
})
|
||||
|
||||
test('decorator metadata', async (t) => {
|
||||
const { getFileContent } = await run(t.title, {
|
||||
test('decorator metadata', async () => {
|
||||
const { getFileContent } = await run(getTestName(), {
|
||||
'input.ts': `
|
||||
function Injectable() {}
|
||||
|
||||
@ -675,12 +677,12 @@ test('decorator metadata', async (t) => {
|
||||
}`,
|
||||
})
|
||||
const contents = await getFileContent('dist/input.js')
|
||||
t.assert(contents.includes(`Reflect.metadata("design:type"`))
|
||||
expect(contents).toContain(`Reflect.metadata("design:type"`)
|
||||
})
|
||||
|
||||
test('inject style', async (t) => {
|
||||
test('inject style', async () => {
|
||||
const { outFiles, output } = await run(
|
||||
t.title,
|
||||
getTestName(),
|
||||
{
|
||||
'input.ts': `import './style.css'`,
|
||||
'style.css': `.hello { color: red }`,
|
||||
@ -689,13 +691,13 @@ test('inject style', async (t) => {
|
||||
flags: ['--inject-style', '--minify'],
|
||||
}
|
||||
)
|
||||
t.deepEqual(outFiles, ['input.js'])
|
||||
t.assert(output.includes('.hello{color:red}'))
|
||||
expect(outFiles).toEqual(['input.js'])
|
||||
expect(output).toContain('.hello{color:red}')
|
||||
})
|
||||
|
||||
test('inject style in multi formats', async (t) => {
|
||||
test('inject style in multi formats', async () => {
|
||||
const { outFiles, getFileContent } = await run(
|
||||
t.title,
|
||||
getTestName(),
|
||||
{
|
||||
'input.ts': `export * from './App.svelte'`,
|
||||
'App.svelte': `
|
||||
@ -709,15 +711,15 @@ test('inject style in multi formats', async (t) => {
|
||||
flags: ['--inject-style', '--minify', '--format', 'esm,cjs,iife'],
|
||||
}
|
||||
)
|
||||
t.deepEqual(outFiles, ['input.global.js', 'input.js', 'input.mjs'])
|
||||
expect(outFiles).toEqual(['input.global.js', 'input.js', 'input.mjs'])
|
||||
for (const file of outFiles) {
|
||||
t.assert((await getFileContent(`dist/${file}`)).includes('{color:red}'))
|
||||
expect(await getFileContent(`dist/${file}`)).toContain('{color:red}')
|
||||
}
|
||||
})
|
||||
|
||||
test('shebang', async (t) => {
|
||||
test('shebang', async () => {
|
||||
const { outDir } = await run(
|
||||
t.title,
|
||||
getTestName(),
|
||||
{
|
||||
'a.ts': `#!/usr/bin/env node\bconsole.log('a')`,
|
||||
'b.ts': `console.log('b')`,
|
||||
@ -728,20 +730,20 @@ test('shebang', async (t) => {
|
||||
)
|
||||
|
||||
if (process.platform === 'win32') {
|
||||
return t.pass()
|
||||
return
|
||||
}
|
||||
|
||||
t.notThrows(() => {
|
||||
fs.accessSync(join(outDir, 'a.js'), fs.constants.X_OK)
|
||||
})
|
||||
t.throws(() => {
|
||||
fs.accessSync(join(outDir, 'b.js'), fs.constants.X_OK)
|
||||
})
|
||||
expect(() => {
|
||||
fs.accessSync(path.join(outDir, 'a.js'), fs.constants.X_OK)
|
||||
}).not.toThrow()
|
||||
expect(() => {
|
||||
fs.accessSync(path.join(outDir, 'b.js'), fs.constants.X_OK)
|
||||
}).toThrow()
|
||||
})
|
||||
|
||||
test('es5 target', async (t) => {
|
||||
test('es5 target', async () => {
|
||||
const { output, outFiles } = await run(
|
||||
t.title,
|
||||
getTestName(),
|
||||
{
|
||||
'input.ts': `
|
||||
export class Foo {
|
||||
@ -757,13 +759,13 @@ test('es5 target', async (t) => {
|
||||
flags: ['--target', 'es5'],
|
||||
}
|
||||
)
|
||||
t.regex(output, /createClass/)
|
||||
t.deepEqual(outFiles, ['input.js'])
|
||||
expect(output).toMatch(/createClass/)
|
||||
expect(outFiles).toEqual(['input.js'])
|
||||
})
|
||||
|
||||
test('multiple targets', async (t) => {
|
||||
test('multiple targets', async () => {
|
||||
const { output, outFiles } = await run(
|
||||
t.title,
|
||||
getTestName(),
|
||||
{
|
||||
'input.ts': `
|
||||
export const answer = 42
|
||||
@ -774,6 +776,6 @@ test('multiple targets', async (t) => {
|
||||
flags: ['--target', 'es2020,chrome58,firefox57,safari11,edge16'],
|
||||
}
|
||||
)
|
||||
t.snapshot(output)
|
||||
t.deepEqual(outFiles, ['input.js'])
|
||||
expect(output).toMatchSnapshot()
|
||||
expect(outFiles).toEqual(['input.js'])
|
||||
})
|
||||
|
||||
@ -1,493 +0,0 @@
|
||||
# Snapshot report for `test/index.test.ts`
|
||||
|
||||
The actual snapshot is saved in `index.test.ts.snap`.
|
||||
|
||||
Generated by [AVA](https://avajs.dev).
|
||||
|
||||
## simple
|
||||
|
||||
> Snapshot 1
|
||||
|
||||
`var __defProp = Object.defineProperty;␊
|
||||
var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });␊
|
||||
var __export = (target, all) => {␊
|
||||
__markAsModule(target);␊
|
||||
for (var name in all)␊
|
||||
__defProp(target, name, { get: all[name], enumerable: true });␊
|
||||
};␊
|
||||
␊
|
||||
// input.ts␊
|
||||
__export(exports, {␊
|
||||
default: () => input_default␊
|
||||
});␊
|
||||
␊
|
||||
// foo.ts␊
|
||||
var foo_default = "foo";␊
|
||||
␊
|
||||
// input.ts␊
|
||||
var input_default = foo_default;␊
|
||||
// Annotate the CommonJS export names for ESM import in node:␊
|
||||
0 && (module.exports = {});␊
|
||||
`
|
||||
|
||||
## enable --dts-resolve for specific module
|
||||
|
||||
> Snapshot 1
|
||||
|
||||
`export * from 'vue';␊
|
||||
␊
|
||||
type MarkRequired<T, RK extends keyof T> = Exclude<T, RK> & Required<Pick<T, RK>>␊
|
||||
␊
|
||||
export { MarkRequired };␊
|
||||
`
|
||||
|
||||
## multiple formats
|
||||
|
||||
> Snapshot 1
|
||||
|
||||
`var __defProp = Object.defineProperty;␊
|
||||
var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });␊
|
||||
var __export = (target, all) => {␊
|
||||
__markAsModule(target);␊
|
||||
for (var name in all)␊
|
||||
__defProp(target, name, { get: all[name], enumerable: true });␊
|
||||
};␊
|
||||
␊
|
||||
// input.ts␊
|
||||
__export(exports, {␊
|
||||
a: () => a␊
|
||||
});␊
|
||||
var a = 1;␊
|
||||
// Annotate the CommonJS export names for ESM import in node:␊
|
||||
0 && (module.exports = {␊
|
||||
a␊
|
||||
});␊
|
||||
`
|
||||
|
||||
## multiple formats and pkg.type is module
|
||||
|
||||
> Snapshot 1
|
||||
|
||||
`// input.ts␊
|
||||
var a = 1;␊
|
||||
export {␊
|
||||
a␊
|
||||
};␊
|
||||
`
|
||||
|
||||
## multiple formats with legacy output
|
||||
|
||||
> Snapshot 1
|
||||
|
||||
`var __defProp = Object.defineProperty;␊
|
||||
var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });␊
|
||||
var __export = (target, all) => {␊
|
||||
__markAsModule(target);␊
|
||||
for (var name in all)␊
|
||||
__defProp(target, name, { get: all[name], enumerable: true });␊
|
||||
};␊
|
||||
␊
|
||||
// input.ts␊
|
||||
__export(exports, {␊
|
||||
a: () => a␊
|
||||
});␊
|
||||
var a = 1;␊
|
||||
// Annotate the CommonJS export names for ESM import in node:␊
|
||||
0 && (module.exports = {␊
|
||||
a␊
|
||||
});␊
|
||||
`
|
||||
|
||||
## minify
|
||||
|
||||
> Snapshot 1
|
||||
|
||||
`var r=Object.defineProperty;var t=o=>r(o,"__esModule",{value:!0});var e=(o,f)=>{t(o);for(var n in f)r(o,n,{get:f[n],enumerable:!0})};e(exports,{foo:()=>u});function u(){return"foo"}0&&(module.exports={foo});␊
|
||||
`
|
||||
|
||||
## --env flag
|
||||
|
||||
> Snapshot 1
|
||||
|
||||
`var __defProp = Object.defineProperty;␊
|
||||
var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });␊
|
||||
var __export = (target, all) => {␊
|
||||
__markAsModule(target);␊
|
||||
for (var name in all)␊
|
||||
__defProp(target, name, { get: all[name], enumerable: true });␊
|
||||
};␊
|
||||
␊
|
||||
// input.ts␊
|
||||
__export(exports, {␊
|
||||
env: () => env␊
|
||||
});␊
|
||||
var env = "production";␊
|
||||
// Annotate the CommonJS export names for ESM import in node:␊
|
||||
0 && (module.exports = {␊
|
||||
env␊
|
||||
});␊
|
||||
`
|
||||
|
||||
## import css
|
||||
|
||||
> ""
|
||||
|
||||
''
|
||||
|
||||
## import css in --dts
|
||||
|
||||
> Snapshot 1
|
||||
|
||||
''
|
||||
|
||||
## node protocol
|
||||
|
||||
> Snapshot 1
|
||||
|
||||
`var __create = Object.create;␊
|
||||
var __defProp = Object.defineProperty;␊
|
||||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;␊
|
||||
var __getOwnPropNames = Object.getOwnPropertyNames;␊
|
||||
var __getProtoOf = Object.getPrototypeOf;␊
|
||||
var __hasOwnProp = Object.prototype.hasOwnProperty;␊
|
||||
var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });␊
|
||||
var __reExport = (target, module2, desc) => {␊
|
||||
if (module2 && typeof module2 === "object" || typeof module2 === "function") {␊
|
||||
for (let key of __getOwnPropNames(module2))␊
|
||||
if (!__hasOwnProp.call(target, key) && key !== "default")␊
|
||||
__defProp(target, key, { get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable });␊
|
||||
}␊
|
||||
return target;␊
|
||||
};␊
|
||||
var __toModule = (module2) => {␊
|
||||
return __reExport(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", module2 && module2.__esModule && "default" in module2 ? { get: () => module2.default, enumerable: true } : { value: module2, enumerable: true })), module2);␊
|
||||
};␊
|
||||
␊
|
||||
// input.ts␊
|
||||
var import_node_fs = __toModule(require("fs"));␊
|
||||
console.log(import_node_fs.default);␊
|
||||
`
|
||||
|
||||
## external
|
||||
|
||||
> Snapshot 1
|
||||
|
||||
`var __create = Object.create;␊
|
||||
var __defProp = Object.defineProperty;␊
|
||||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;␊
|
||||
var __getOwnPropNames = Object.getOwnPropertyNames;␊
|
||||
var __getProtoOf = Object.getPrototypeOf;␊
|
||||
var __hasOwnProp = Object.prototype.hasOwnProperty;␊
|
||||
var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });␊
|
||||
var __export = (target, all) => {␊
|
||||
__markAsModule(target);␊
|
||||
for (var name in all)␊
|
||||
__defProp(target, name, { get: all[name], enumerable: true });␊
|
||||
};␊
|
||||
var __reExport = (target, module2, desc) => {␊
|
||||
if (module2 && typeof module2 === "object" || typeof module2 === "function") {␊
|
||||
for (let key of __getOwnPropNames(module2))␊
|
||||
if (!__hasOwnProp.call(target, key) && key !== "default")␊
|
||||
__defProp(target, key, { get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable });␊
|
||||
}␊
|
||||
return target;␊
|
||||
};␊
|
||||
var __toModule = (module2) => {␊
|
||||
return __reExport(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", module2 && module2.__esModule && "default" in module2 ? { get: () => module2.default, enumerable: true } : { value: module2, enumerable: true })), module2);␊
|
||||
};␊
|
||||
␊
|
||||
// input.ts␊
|
||||
__export(exports, {␊
|
||||
bar: () => import_bar.bar,␊
|
||||
baz: () => baz,␊
|
||||
foo: () => import_foo.foo␊
|
||||
});␊
|
||||
var import_foo = __toModule(require("foo"));␊
|
||||
var import_bar = __toModule(require("bar"));␊
|
||||
␊
|
||||
// node_modules/baz/index.ts␊
|
||||
var baz = "baz";␊
|
||||
// Annotate the CommonJS export names for ESM import in node:␊
|
||||
0 && (module.exports = {␊
|
||||
bar,␊
|
||||
baz,␊
|
||||
foo␊
|
||||
});␊
|
||||
`
|
||||
|
||||
## disable code splitting to get proper module.exports =
|
||||
|
||||
> Snapshot 1
|
||||
|
||||
`// input.ts␊
|
||||
module.exports = 123;␊
|
||||
`
|
||||
|
||||
## bundle svelte
|
||||
|
||||
> output
|
||||
|
||||
`var __create = Object.create;␊
|
||||
var __defProp = Object.defineProperty;␊
|
||||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;␊
|
||||
var __getOwnPropNames = Object.getOwnPropertyNames;␊
|
||||
var __getProtoOf = Object.getPrototypeOf;␊
|
||||
var __hasOwnProp = Object.prototype.hasOwnProperty;␊
|
||||
var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });␊
|
||||
var __export = (target, all) => {␊
|
||||
__markAsModule(target);␊
|
||||
for (var name in all)␊
|
||||
__defProp(target, name, { get: all[name], enumerable: true });␊
|
||||
};␊
|
||||
var __reExport = (target, module2, desc) => {␊
|
||||
if (module2 && typeof module2 === "object" || typeof module2 === "function") {␊
|
||||
for (let key of __getOwnPropNames(module2))␊
|
||||
if (!__hasOwnProp.call(target, key) && key !== "default")␊
|
||||
__defProp(target, key, { get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable });␊
|
||||
}␊
|
||||
return target;␊
|
||||
};␊
|
||||
var __toModule = (module2) => {␊
|
||||
return __reExport(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", module2 && module2.__esModule && "default" in module2 ? { get: () => module2.default, enumerable: true } : { value: module2, enumerable: true })), module2);␊
|
||||
};␊
|
||||
␊
|
||||
// input.ts␊
|
||||
__export(exports, {␊
|
||||
App: () => App_default␊
|
||||
});␊
|
||||
␊
|
||||
// App.svelte␊
|
||||
var import_internal = __toModule(require("svelte/internal"));␊
|
||||
function create_fragment(ctx) {␊
|
||||
let span;␊
|
||||
return {␊
|
||||
c() {␊
|
||||
span = (0, import_internal.element)("span");␊
|
||||
span.textContent = \`${msg}\`;␊
|
||||
(0, import_internal.attr)(span, "class", "svelte-1jo4k3z");␊
|
||||
},␊
|
||||
m(target, anchor) {␊
|
||||
(0, import_internal.insert)(target, span, anchor);␊
|
||||
},␊
|
||||
p: import_internal.noop,␊
|
||||
i: import_internal.noop,␊
|
||||
o: import_internal.noop,␊
|
||||
d(detaching) {␊
|
||||
if (detaching)␊
|
||||
(0, import_internal.detach)(span);␊
|
||||
}␊
|
||||
};␊
|
||||
}␊
|
||||
var msg = "hello svelte";␊
|
||||
var App = class extends import_internal.SvelteComponent {␊
|
||||
constructor(options) {␊
|
||||
super();␊
|
||||
(0, import_internal.init)(this, options, null, create_fragment, import_internal.safe_not_equal, {});␊
|
||||
}␊
|
||||
};␊
|
||||
var App_default = App;␊
|
||||
// Annotate the CommonJS export names for ESM import in node:␊
|
||||
0 && (module.exports = {␊
|
||||
App␊
|
||||
});␊
|
||||
`
|
||||
|
||||
> css
|
||||
|
||||
`/* svelte-css:App.svelte.css */␊
|
||||
span.svelte-1jo4k3z {␊
|
||||
color: red;␊
|
||||
}␊
|
||||
`
|
||||
|
||||
## support baseUrl and paths in tsconfig.json
|
||||
|
||||
> Snapshot 1
|
||||
|
||||
`var __defProp = Object.defineProperty;␊
|
||||
var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });␊
|
||||
var __export = (target, all) => {␊
|
||||
__markAsModule(target);␊
|
||||
for (var name in all)␊
|
||||
__defProp(target, name, { get: all[name], enumerable: true });␊
|
||||
};␊
|
||||
␊
|
||||
// input.ts␊
|
||||
__export(exports, {␊
|
||||
foo: () => foo␊
|
||||
});␊
|
||||
␊
|
||||
// foo.ts␊
|
||||
var foo = "foo";␊
|
||||
// Annotate the CommonJS export names for ESM import in node:␊
|
||||
0 && (module.exports = {␊
|
||||
foo␊
|
||||
});␊
|
||||
`
|
||||
|
||||
## support baseUrl and paths in tsconfig.json in --dts build
|
||||
|
||||
> Snapshot 1
|
||||
|
||||
`declare const foo = "foo";␊
|
||||
␊
|
||||
export { foo };␊
|
||||
`
|
||||
|
||||
## support baseUrl and paths in tsconfig.json in --dts-resolve build
|
||||
|
||||
> Snapshot 1
|
||||
|
||||
`declare const foo = "foo";␊
|
||||
␊
|
||||
export { foo };␊
|
||||
`
|
||||
|
||||
## transform import.meta.url in cjs format
|
||||
|
||||
> Snapshot 1
|
||||
|
||||
`var __defProp = Object.defineProperty;␊
|
||||
var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });␊
|
||||
var __export = (target, all) => {␊
|
||||
__markAsModule(target);␊
|
||||
for (var name in all)␊
|
||||
__defProp(target, name, { get: all[name], enumerable: true });␊
|
||||
};␊
|
||||
␊
|
||||
// input.ts␊
|
||||
__export(exports, {␊
|
||||
default: () => input_default␊
|
||||
});␊
|
||||
␊
|
||||
// ../../../assets/cjs_shims.js␊
|
||||
var getImportMetaUrl = () => typeof document === "undefined" ? new URL("file:" + __filename).href : document.currentScript && document.currentScript.src || new URL("main.js", document.baseURI).href;␊
|
||||
var importMetaUrl = /* @__PURE__ */ getImportMetaUrl();␊
|
||||
␊
|
||||
// input.ts␊
|
||||
var input_default = importMetaUrl;␊
|
||||
// Annotate the CommonJS export names for ESM import in node:␊
|
||||
0 && (module.exports = {});␊
|
||||
`
|
||||
|
||||
## transform __dirname, __filename in esm format
|
||||
|
||||
> Snapshot 1
|
||||
|
||||
`// ../../../assets/esm_shims.js␊
|
||||
import { fileURLToPath } from "url";␊
|
||||
import path from "path";␊
|
||||
var getFilename = () => fileURLToPath(import.meta.url);␊
|
||||
var getDirname = () => path.dirname(getFilename());␊
|
||||
var __dirname = /* @__PURE__ */ getDirname();␊
|
||||
var __filename = /* @__PURE__ */ getFilename();␊
|
||||
␊
|
||||
// input.ts␊
|
||||
var a = __dirname;␊
|
||||
var b = __filename;␊
|
||||
export {␊
|
||||
a,␊
|
||||
b␊
|
||||
};␊
|
||||
`
|
||||
|
||||
## code splitting in cjs format
|
||||
|
||||
> Snapshot 1
|
||||
|
||||
`"use strict";Object.defineProperty(exports, "__esModule", {value: true});␊
|
||||
␊
|
||||
␊
|
||||
var _chunk56VUBPK5js = require('./chunk-56VUBPK5.js');␊
|
||||
␊
|
||||
// input.ts␊
|
||||
var foo = () => Promise.resolve().then(() => _chunk56VUBPK5js.__toModule.call(void 0, _chunk56VUBPK5js.__require.call(void 0, "./foo-UAUJLGDY.js")));␊
|
||||
␊
|
||||
␊
|
||||
exports.foo = foo;␊
|
||||
`
|
||||
|
||||
> Snapshot 2
|
||||
|
||||
`"use strict";Object.defineProperty(exports, "__esModule", {value: true});␊
|
||||
␊
|
||||
␊
|
||||
var _chunk56VUBPK5js = require('./chunk-56VUBPK5.js');␊
|
||||
␊
|
||||
// another-input.ts␊
|
||||
var foo = () => Promise.resolve().then(() => _chunk56VUBPK5js.__toModule.call(void 0, _chunk56VUBPK5js.__require.call(void 0, "./foo-UAUJLGDY.js")));␊
|
||||
␊
|
||||
␊
|
||||
exports.foo = foo;␊
|
||||
`
|
||||
|
||||
## declaration files with multiple entrypoints #316
|
||||
|
||||
> dist/index.d.ts
|
||||
|
||||
`declare const foo = 1;␊
|
||||
␊
|
||||
export { foo };␊
|
||||
`
|
||||
|
||||
> dist/bar/index.d.ts
|
||||
|
||||
`declare const bar = "bar";␊
|
||||
␊
|
||||
export { bar };␊
|
||||
`
|
||||
|
||||
## es5 target
|
||||
|
||||
> Snapshot 1
|
||||
|
||||
`var __defProp = Object.defineProperty;␊
|
||||
var __markAsModule = function (target) { return __defProp(target, "__esModule", { value: true }); };␊
|
||||
var __export = function (target, all) {␊
|
||||
__markAsModule(target);␊
|
||||
for (var name in all)␊
|
||||
{ __defProp(target, name, { get: all[name], enumerable: true }); }␊
|
||||
};␊
|
||||
␊
|
||||
// input.ts␊
|
||||
__export(exports, {␊
|
||||
Foo: function () { return Foo; }␊
|
||||
});␊
|
||||
var Foo = /*@__PURE__*/(function () {␊
|
||||
function Foo () {}␊
|
||||
␊
|
||||
Foo.prototype.hi = function hi () {␊
|
||||
var a = function () { return "foo"; };␊
|
||||
console.log(a());␊
|
||||
};␊
|
||||
␊
|
||||
return Foo;␊
|
||||
}());␊
|
||||
// Annotate the CommonJS export names for ESM import in node:␊
|
||||
0 && (module.exports = {␊
|
||||
Foo: Foo␊
|
||||
});␊
|
||||
`
|
||||
|
||||
## multiple targets
|
||||
|
||||
> Snapshot 1
|
||||
|
||||
`var __defProp = Object.defineProperty;␊
|
||||
var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });␊
|
||||
var __export = (target, all) => {␊
|
||||
__markAsModule(target);␊
|
||||
for (var name in all)␊
|
||||
__defProp(target, name, { get: all[name], enumerable: true });␊
|
||||
};␊
|
||||
␊
|
||||
// input.ts␊
|
||||
__export(exports, {␊
|
||||
answer: () => answer␊
|
||||
});␊
|
||||
var answer = 42;␊
|
||||
// Annotate the CommonJS export names for ESM import in node:␊
|
||||
0 && (module.exports = {␊
|
||||
answer␊
|
||||
});␊
|
||||
`
|
||||
Binary file not shown.
@ -2,8 +2,8 @@
|
||||
"compilerOptions": {
|
||||
/* Basic Options */
|
||||
// "incremental": true, /* Enable incremental compilation */
|
||||
"target": "es2018" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */,
|
||||
"module": "commonjs" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */,
|
||||
"target": "esnext" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */,
|
||||
"module": "esnext" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */,
|
||||
// "lib": [], /* Specify library files to be included in the compilation. */
|
||||
// "allowJs": true, /* Allow javascript files to be compiled. */
|
||||
// "checkJs": true, /* Report errors in .js files. */
|
||||
@ -39,7 +39,7 @@
|
||||
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
|
||||
|
||||
/* Module Resolution Options */
|
||||
// "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
|
||||
"moduleResolution": "node" /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */,
|
||||
// "baseUrl": "./", /* Base directory to resolve non-absolute module names. */
|
||||
// "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
|
||||
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
|
||||
|
||||
9
vitest.config.ts
Normal file
9
vitest.config.ts
Normal file
@ -0,0 +1,9 @@
|
||||
import { UserConfig } from 'vitest'
|
||||
|
||||
const config: { test: UserConfig } = {
|
||||
test: {
|
||||
testTimeout: 50000,
|
||||
},
|
||||
}
|
||||
|
||||
export default config
|
||||
Loading…
x
Reference in New Issue
Block a user