Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
test('addCounts() updates a coverage report with usage data', async t => {
const filename = resolve('fixtures/foo.js')
const { code, hash, reportingCode } = instrument({
code: readFileSync(filename, 'utf8'),
filename
})
const stream = await run(code, filename, exports => {
exports.foo()
exports.foo()
exports.bar()
})
const report = requireFromString(reportingCode).getInitialCoverage()
const data = await collectUsageData(stream)
addCounts(report, data[hash])
const { s, b, f } = report
t.deepEqual(s, {
1: 1,
2: 2,
3: 1,
4: 1,
5: 1,
6: 0
})
t.deepEqual(b, {})
t.deepEqual(f, {
1: 2,
2: 1,
test('exports getInitialCoverage()', t => {
const exports = requireFromString(transform``)
t.true(typeof exports.getInitialCoverage === 'function')
})
const moduleResponse = await fetchModuleContent(url);
let nodeModule;
try {
checkStatus(moduleResponse);
const moduleString = await moduleResponse.text();
if (process.env.NODE_ENV === 'production') {
const actualSRI = ssri.fromData(
moduleString,
{ algorithms: ['sha256', 'sha384'] }
).toString();
assert(integrity === actualSRI, `SRI for module at ${url} must match SRI in module map.\n Expected ${integrity}, received ${actualSRI}`);
}
nodeModule = requireFromString(moduleString, url);
} catch (err) {
if (err.shouldBlockModuleReload !== false) {
addToModuleBlockList(url);
console.warn(`Holocron module at ${url} added to blocklist: ${err.message}`);
}
throw err;
}
onModuleLoad({
moduleName,
module: nodeModule,
});
return nodeModule;
} catch (e) {
console.log(`Failed to load Holocron module at ${url}`);
compiler.run((err, stats) => {
if (err) {
return console.log(err);
}
console.log('Loading site data...')
const fileContent = memoryFS.readFileSync("/site-bundle.js").toString('utf8');
requireFromString('var window = {}; '+fileContent, path.join(packageRoot, 'site-bundle.js')).default.then(site => {
console.log('Loaded.')
let cssFile;
const files = memoryFS.readdirSync("/")
const bundlePattern = /^site-bundle\.([a-z0-9]{8})\.css$/
for (let i = 0, len = files.length; i < len; i++) {
const name = files[i]
const matches = name.match(bundlePattern)
if (name === 'site-bundle.js') {
continue
}
if (matches) {
cssFile = name;
}
console.log(`Creating "${name}"...`)
configFile: false,
filename: id,
presets: [
[
require('@babel/preset-env'),
{
targets: {
node: 'current'
}
}
],
id.endsWith('.ts') && require('@babel/preset-typescript')
].filter(Boolean)
}
)
const m = requireFromString(content && content.code ? content.code : '', id)
return m.default || m
}
})
function getServer(filename: string, buffer: Buffer) {
const serverString = requireFromString(buffer.toString(), filename);
const server = requireDefault(serverString);
if (Object.getPrototypeOf(server) === express) {
throw new Error("Module is not of type Express");
}
return server as Express;
}
const getServer = (filename: string, buffer: Buffer) => {
const serverString = requireFromString(buffer.toString(), filename);
const server = interopRequireDefault(serverString);
if (Object.getPrototypeOf(server) === express) {
throw new Error("Module is not of type Express");
}
return server as Express;
};
const output = entries.reduce((res, e) => {
const str = mfs.readFileSync(e, 'utf8');
const Component = requireFromString(str);
return {
...res,
[e]: Component,
};
}, {});