Last active
November 18, 2019 17:05
-
-
Save c0bra/ad46a88f3ebc13d1f3662ef401a9a770 to your computer and use it in GitHub Desktop.
Testing Svelte with Jest
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"jest": { | |
"testMatch": [ | |
"**/test/**/*.js" | |
], | |
"transform": { | |
"\\.js$": "babel-jest", | |
"\\.(html|svelte)$": "./test/transform" | |
}, | |
"transformIgnorePatterns": [ | |
"/node_modules/(?!svelte).+\\.js$" | |
], | |
"moduleFileExtensions": [ | |
"js", | |
"json", | |
"html", | |
"svelte" | |
] | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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