Skip to content

Commit aefed07

Browse files
fix: test
1 parent ca81961 commit aefed07

2 files changed

Lines changed: 16 additions & 15 deletions

File tree

test/source/test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* ©️ 2016 - present FlowCrypt a.s. Limitations apply. Contact human@flowcrypt.com */
22

3-
import test from 'ava';
3+
import test, { Implementation } from 'ava';
44
import { exec } from 'child_process';
55
import { promisify } from 'util';
66

@@ -59,7 +59,7 @@ const testWithBrowser = (
5959
cb: (t: AvaContext, browser: BrowserHandle) => Promise<void>,
6060
flag?: 'FAILING',
6161
timeout = consts.TIMEOUT_EACH_RETRY
62-
) => {
62+
): Implementation<unknown[]> => {
6363
return async (t: AvaContext) => {
6464
const mockApi = isMock ? await startMockApiAndCopyBuild(t) : undefined;
6565
if (isMock) {

tooling/resolve-modules.ts

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,16 @@ export interface TSConfig {
2222
}
2323

2424
const { compilerOptions } = JSON.parse(readFileSync(tsconfigPath || './tsconfig.json').toString()) as TSConfig;
25-
const moduleMap: { [name: string]: string | null } = {};
25+
const moduleMap: { [name: string]: string | undefined } = {};
26+
const commentImportedModules = new Set<string>();
2627
for (const moduleName of Object.keys(compilerOptions.paths)) {
2728
if (compilerOptions.paths[moduleName].some((x: string) => x.endsWith('/COMMENT'))) {
2829
// COMMENT flag, remove such import statements from the code, because they will be imported with script tags for compatibility
29-
moduleMap[moduleName] = null; // eslint-disable-line no-null/no-null
30+
commentImportedModules.add(moduleName);
3031
} else {
3132
// replace import with full path from config
32-
const selectedPath = compilerOptions.paths[moduleName].find((x: string) => /\.(mjs|js)$/.exec(x) !== null);
33-
moduleMap[moduleName] = selectedPath?.replace(/^\.\/extension\//, '') || null; // eslint-disable-line no-null/no-null
33+
const selectedPath = compilerOptions.paths[moduleName].find((x: string) => /\.(mjs|js)$/.test(x));
34+
moduleMap[moduleName] = selectedPath?.replace(/^\.\/extension\//, '');
3435
}
3536
}
3637

@@ -41,18 +42,18 @@ const importLineEndingWithJsNotStartingWithDot = /^(?!\s*\/\/)(?!\s*\/\*)(?:\s*i
4142

4243
const resolveLineImports = (regex: RegExp, line: string, path: string) =>
4344
line.replace(regex, (found, prefix, libname: string, suffix) => {
44-
// eslint-disable-next-line no-null/no-null
45-
if (moduleMap[libname] === null) {
45+
if (commentImportedModules.has(libname)) {
4646
return `// ${prefix}${libname}${suffix} // commented during build process: imported with script tag`;
47-
} else if (!moduleMap[libname]) {
47+
}
48+
const mappedModulePath = moduleMap[libname];
49+
if (!mappedModulePath) {
4850
return found;
49-
} else {
50-
const depth = path.split(sep).length;
51-
const prePath = '../'.repeat(depth - 3); // todo:
52-
const resolved = `${prefix}${prePath}${moduleMap[libname]}${suffix}`;
53-
// console.info(`${path}: ${found} -> ${resolved}`);
54-
return resolved;
5551
}
52+
const depth = path.split(sep).length;
53+
const prePath = '../'.repeat(depth - 3); // todo:
54+
const resolved = `${prefix}${prePath}${mappedModulePath}${suffix}`;
55+
// console.info(`${path}: ${found} -> ${resolved}`);
56+
return resolved;
5657
});
5758

5859
const errIfSrcMissingJsExtensionInImport = (src: string, path: string) => {

0 commit comments

Comments
 (0)