Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
await runInTmpAsync("pkg", async dir => {
const srcPath = pathlib.resolve(pathlib.join(dir, "a.ts"));
fs.writeFileSync(srcPath, 'export const aVal: string = "ABC";');
let output = conv.convert("", `import {aVal} from "./${dir}/a";`);
expect(output.diagnostics).toEqual([]);
expect(output.sideOutputs).toEqual([
{
path: pathlib.join(process.cwd(), `${dir}/a.js`),
data: buildOutput(['exports.aVal = "ABC";'])
}
]);
fs.writeFileSync(srcPath, 'export const aVal: string = "XYZ";');
await waitFileEvent(srcPath, ts.FileWatcherEventKind.Changed);
// yield to TyeScript compiler just for safety.
await sleep(0);
output = conv.convert("", `import {aVal} from "./${dir}/a";`);
expect(output.diagnostics).toEqual([]);
expect(output.sideOutputs).toEqual([
{
path: pathlib.join(process.cwd(), `${dir}/a.js`),
data: buildOutput(['exports.aVal = "XYZ";'])
}
]);
});
});
function updateContent(decls: string, src: string) {
declContent = decls;
srcContent = src;
builder = null;
// TODO: Notify updates only when src is really updated,
// unless there is another cache layer in watcher API.
notifyUpdateSrc(srcFilename, ts.FileWatcherEventKind.Changed);
notifyUpdateDecls(declFilename, ts.FileWatcherEventKind.Changed);
if (!rebuildTimer) {
throw new Error("rebuildTimer is not set properly");
}
rebuildTimer.callback();
rebuildTimer = null;
if (!builder) {
throw new Error("builder is not recreated");
}
}
await runInTmpAsync("pkg", async dir => {
const srcPath = pathlib.resolve(pathlib.join(dir, "a.ts"));
fs.writeFileSync(srcPath, 'export const aVal = "ABC";');
let promise = ex.execute(`import {aVal} from "./${dir}/a";`);
expect(await promise).toBe(true);
expect(consoleLogCalls).toEqual([]);
expect(consoleErrorCalls).toEqual([]);
expect(ex.locals.aVal).toEqual("ABC");
fs.writeFileSync(srcPath, 'export const aVal = "XYZ";');
await waitFileEvent(srcPath, ts.FileWatcherEventKind.Changed);
// yield to TyeScript compiler just for safety.
await sleep(0);
promise = ex.execute(`import {aVal} from "./${dir}/a";`);
expect(await promise).toBe(true);
expect(consoleLogCalls).toEqual([]);
expect(consoleErrorCalls).toEqual([]);
expect(ex.locals.aVal).toEqual("XYZ");
});
});