mirror of
https://github.com/qlik-oss/nebula.js.git
synced 2025-12-19 09:48:18 -05:00
feat: add test-utils package (#279)
This commit is contained in:
1
apis/test-utils/index.js
Normal file
1
apis/test-utils/index.js
Normal file
@@ -0,0 +1 @@
|
||||
module.exports = require('./dist/test-utils.js');
|
||||
32
apis/test-utils/package.json
Normal file
32
apis/test-utils/package.json
Normal 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"
|
||||
}
|
||||
}
|
||||
46
apis/test-utils/src/index.js
Normal file
46
apis/test-utils/src/index.js
Normal 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 [];
|
||||
},
|
||||
};
|
||||
}
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user