This is a step-by-step guide on how to use @esmbly/transformer-v8
.
Start off by creating a new directory for this example, and navigate into it.
mkdir v8-example
cd v8-example
# Using Yarn:
yarn init --yes
# Or, using NPM:
npm init --yes
# Using Yarn:
yarn add @esmbly/cli @esmbly/transformer-v8
# Or, using NPM:
npm install @esmbly/cli @esmbly/transformer-v8 --save
Create the following files:
- The configuration file:
esmbly.config.js
- The example program:
src/add.js
mkdir src
touch src/add.js
touch esmbly.config.js
Add the following to your newly created esmbly.config.js
.
const V8 = require('@esmbly/transformer-v8');
module.exports = {
input: ['./src/**/*.js'],
transformers: [
V8.createTransformer(),
],
output: [
{
format: '.ts',
outDir: 'dist',
rootDir: 'src',
},
],
};
Add the following to src/add.js
function add(a, b) {
return a + b;
}
module.exports.add = add;
# Using Yarn:
yarn add jest
# Or, using NPM:
npm install jest --save
Open esmbly.config.js
and set the testCommand
option to 'jest'
when creating the transformer instance.
transformers: [
V8.createTransformer({ testCommand: 'jest' }),
],
Create a test file.
mkdir tests
touch tests/add.test.js
Add the following to tests/add.test.js
.
const { add } = require('../src/add.js');
describe('add', () => {
it('adds two numbers', () => {
expect(add(2, 3)).toEqual(5);
});
});
# Using Yarn:
yarn add jasmine
# Or, using NPM:
npm install jasmine --save
Open esmbly.config.js
and set the testCommand
option to 'jasmine'
when creating the transformer instance.
transformers: [
V8.createTransformer({ testCommand: 'jasmine tests/add.test.js' }),
],
Create a test file.
mkdir tests
touch tests/add.test.js
Add the following to tests/add.test.js
.
const { add } = require('../src/add.js');
describe('add', () => {
it('adds two numbers', () => {
expect(add(2, 3)).toEqual(5);
});
});
# Using Yarn:
yarn add tape
# Or, using NPM:
npm install tape --save
Open esmbly.config.js
and set the testCommand
option to 'tape'
when creating the transformer instance.
transformers: [
V8.createTransformer({ testCommand: 'tape tests/add.test.js' }),
],
Create a test file.
mkdir tests
touch tests/add.test.js
Add the following to tests/add.test.js
.
const test = require('tape');
const { add } = require('../src/add.js');
test('add', t => {
t.plan(1);
t.equal(add(2, 3), 5);
});
Run Esmbly to output TypeScript files to the dist
directory.
# Using Yarn:
yarn run esmbly run
# Using NPM:
./node_modules/.bin/esmbly run
# Or, using NPX:
npx esmbly run
Esmbly will run the provided test command in a child process. If the test command fails (non zero exit code), Esmbly will tell you. If you need to debug whats being printed to stdout/stderr during the test run, set the debug
option to true when creating the transformer instance.
transformers: [
V8.createTransformer({ testCommand: 'jest', debug: 'true' }),
],