Skip to content

Instantly share code, notes, and snippets.

@c0bra
Last active November 18, 2019 17:05
Show Gist options
  • Save c0bra/ad46a88f3ebc13d1f3662ef401a9a770 to your computer and use it in GitHub Desktop.
Save c0bra/ad46a88f3ebc13d1f3662ef401a9a770 to your computer and use it in GitHub Desktop.
Testing Svelte with Jest
const rollup = require('rollup');
const esm = require('esm');
const { config } = esm(module)('../rollup.config');
function generateOptions(filePath, name) {
return {
input: { input: filePath, plugins: config.plugins },
output: {
file: `./dist/test/${name}.js`,
format: 'cjs',
},
};
}
function compile(filePath, name) {
const { input, output } = generateOptions(filePath, name);
return rollup.rollup(input)
.then(bundle => bundle.generate(output));
}
module.exports = { compile };
{
"jest": {
"testMatch": [
"**/test/**/*.js"
],
"transform": {
"\\.js$": "babel-jest",
"\\.(html|svelte)$": "./test/transform"
},
"transformIgnorePatterns": [
"/node_modules/(?!svelte).+\\.js$"
],
"moduleFileExtensions": [
"js",
"json",
"html",
"svelte"
]
}
}
const deasync = require('deasync');
const { compile } = require('./compile');
module.exports.process = (_s, filePath, _c, _o) => {
let code, map;
compile(filePath, 'App', {}).then(comp => {
code = comp.code;
map = comp.map;
});
deasync.loopWhile(() => !code && !map);
return { code, map };
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment