feat: add test-utils package (#279)

This commit is contained in:
Miralem Drek
2020-01-29 09:47:14 +01:00
committed by GitHub
parent 83310ded82
commit 89338bab90
4 changed files with 85 additions and 2 deletions

1
apis/test-utils/index.js Normal file
View File

@@ -0,0 +1 @@
module.exports = require('./dist/test-utils.js');

View File

@@ -0,0 +1,32 @@
{
"name": "@nebula.js/test-utils",
"version": "0.1.0-alpha.27",
"description": "",
"license": "MIT",
"author": "QlikTech International AB",
"keywords": [],
"publishConfig": {
"access": "public"
},
"repository": {
"type": "git",
"url": "https://github.com/qlik-oss/nebula.js.git",
"directory": "apis/test-utils"
},
"main": "index.js",
"files": [
"dist"
],
"scripts": {
"build": "cross-env NODE_ENV=production rollup --config ../../rollup.config.js",
"build:dev": "rollup --config ../../rollup.config.js",
"build:watch": "rollup --config ../../rollup.config.js -w",
"prepublishOnly": "rm -rf dist && yarn run build"
},
"peerDependencies": {
"@nebula.js/supernova": "0.1.0-alpha.27"
},
"devDependencies": {
"regenerator-runtime": "0.13.3"
}
}

View File

@@ -0,0 +1,46 @@
/* eslint import/prefer-default-export:0 */
import 'regenerator-runtime/runtime'; // temporary polyfill for transpiled async/await in supernova
import { hook } from '@nebula.js/supernova';
if (!global.requestAnimationFrame) {
global.requestAnimationFrame = cb => setTimeout(cb, 10);
global.cancelAnimationFrame = id => clearTimeout(id);
}
export function create(definition, context = {}) {
const hooked = hook(definition);
const component = {
context: {
...context,
},
env: {
translator: context.translator,
},
fn: hooked.fn,
};
hooked.initiate(component);
return {
update(ctx) {
if (ctx) {
Object.assign(component.context, ctx);
}
if (ctx && ctx.translator) {
component.env.translator = ctx.translator;
}
return hooked.run(component);
},
unmount() {
return hooked.teardown(component);
},
takeSnapshot() {
return hooked.runSnaps(component, component.context.layout);
},
actions() {
// TODO
return [];
},
};
}

View File

@@ -115,7 +115,7 @@ const config = (isEsm, dev = false) => {
output: {
file: path.resolve(targetDir, getFileName(isEsm ? 'esm' : '', dev)),
format: isEsm ? 'esm' : 'umd',
exports: targetName === 'supernova' ? 'named' : 'default',
exports: ['supernova', 'test-utils'].indexOf(targetName) !== -1 ? 'named' : 'default',
name: umdName,
sourcemap: false,
banner,
@@ -197,7 +197,7 @@ const config = (isEsm, dev = false) => {
return cfg;
};
const dist = [
let dist = [
// production
watch ? false : config(),
// dev
@@ -209,4 +209,8 @@ const dist = [
pkg.module ? config(true, true) : false,
];
if (targetName === 'test-utils') {
dist = [config(false)];
}
module.exports = dist.filter(Boolean);