export-tester
v1.0.13
Published
Can your code run in ESM, CJS or browser?
Maintainers
Readme
Export Tester

This tool can test if your code can be import well in defferent environment.
Environments supported:
tsTypescriptnode-cjsCommonJS running in Nodenode-esmES Module running in Nodewebpack-cjsCommonJS bundled by webpackwebpack-esmES Module bundled by webpack
This test tool had been tested by the tests of this test tool.
Install
npm i export-testerImport
CommonJS
const tester = require('export-tester');Typescript
import tester = require('export-tester');ES Module
import tester from 'export-tester';Usage
/// <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":
| ...
|