This tool can test if your code can be import well in defferent environment.
Environments supported:
ts
Typescriptnode-cjs
CommonJS running in Nodenode-esm
ES Module running in Nodewebpack-cjs
CommonJS bundled by webpackwebpack-esm
ES Module bundled by webpack
This test tool had been tested by the tests of this test tool.
npm i export-tester
const tester = require('export-tester');
import tester = require('export-tester');
import tester from 'export-tester';
/// <reference path="export-tester/lib/tool.d.ts" />
/// <reference path="some-mod/declaration.d.ts" />
// (If the module tested provide.)
require('export-tester')(
{
sign: 'someMod', // The identifier of module imported.
file: `${__dirname}/lib/index.js`, // Entry file.
req: ['ts', 'node-esm'], // Test environments.
},
{
logMod() { log(someMod); },
checkDef() { log(someMod.default); },
// ...
},
).then(({ err, detail }) => {
if (err) console.error(detail);
process.exit(err);
});
Output:
+-------------------
| Node ESM
| D:\...\export-tester\lib\test\node.mjs
|
+-"logMod":
| ...
|
+-"checkDef":
| ...
|
+-------------------
| TS
| Testing cli
| Compiling
| D:\...\export-tester\lib\test\test.js
| D:\...\export-tester\lib\test\test.ts
|
+-"logMod":
| ...
|
+-"checkDef":
| ...
|