Available as
- Install package
$ npm install -D babel-plugin-test-internal
$ yarn add -D babel-plugin-test-internal
- Add the plugin to Babel configuration in your
babel.config.js
// configuration example
module.exports = api => {
// 1. π are we in a test context?
const isTest = api.env('test')
// 2. if yes register the plugin π
const plugins = isTest ? ["test-internal"]: []
return {
presets: [
"@babel/preset-env",
"@babel/preset-typescript",
"@babel/preset-react",
],
plugins, // π 3. don't forget to add the plugins property to the configuration object
}
}
- In your code, where you want to use internal content (i.e: your tests)
// 1. π import __internal__ from the module you want to test
import {__internal__} from "./your-file"
test("testing some internal things", () => {
const expected = ...
// 2. use properties you need π
assert(__internal__.doSomething(), expected)
})
- Install package
$ npm install -D typescript-plugin-test-internal
$ yarn add -D typescript-plugin-test-internal
- Add the plugin to ts-loader configuration in your
webpack.config.js
// configuration example
// π 1. import the plugin
const testInternalTranformer = require('typescript-plugin-test-internal').default;
module.exports = {
mode: 'development',
entry: './index.ts',
module: {
rules: [
{
test: /\.ts$/,
loader: 'ts-loader',
options: { // π 2. add ts-loader 'options' object
// 3. π add the method 'getCustomTransformers'
getCustomTransformers: program => ({
// 4. register the plugin π
before: [testInternalTransformer(program)]
})
}
}
]
}
}
- In your code, where you want to use internal content (i.e: your tests)
// 1. π import '__internal__' from the module you want to test
import {__internal__} from "./your-file"
test("testing some internal things", () => {
const expected = ...
// 2. use properties you need π
assert(__internal__.doSomething(), expected)
})
Install all dependencies, build and test everything
# from the project root
$ yarn install
$ yarn build
$ yarn test
$ cd ./babel
$ yarn install
$ yarn test
$ yarn build
$ cd ./typescript
$ yarn install
$ yarn test
$ yarn build