Skip to content

Commit

Permalink
debug tests working again, npm serve broken
Browse files Browse the repository at this point in the history
  • Loading branch information
patrick-rodgers committed Dec 16, 2021
1 parent 2947149 commit 448310a
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 22 deletions.
12 changes: 3 additions & 9 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@
"--experimental-loader",
"file://${workspaceRoot}/build/debugging/tools/local-module-resolver/esm-debug.js"
],
"env": {
"NODE_ENV": "development"
},
"console": "internalConsole",
"internalConsoleOptions": "openOnSessionStart",
"sourceMaps": true,
Expand All @@ -32,20 +29,17 @@
"name": "Debug Tests",
"type": "node",
"request": "launch",
"program": "${workspaceRoot}/node_modules/mocha/bin/_mocha",
"program": "${workspaceRoot}/node_modules/mocha/bin/mocha",
"cwd": "${workspaceRoot}",
"preLaunchTask": "test-build",
"runtimeArgs": [
"--experimental-loader",
"file://${workspaceRoot}/build/testing/tools/local-module-resolver/esm-test.js"
],
"sourceMaps": true,
"outFiles": [],
"args": [
"--retries",
"0",
"--verbose",
"--logging"
"--logging",
"--skip-web"
],
"console": "internalConsole",
"internalConsoleOptions": "openOnSessionStart",
Expand Down
4 changes: 2 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
"files.exclude": {
"**/.git": true,
"**/.DS_Store": true,
"**/node_modules": false,
"**/node_modules": true,
"coverage": true,
".nyc_output": true,
"build": false,
"build": true,
"dist": true,
"site": true,
"buildsystem-config.js": true
Expand Down
16 changes: 15 additions & 1 deletion tools/local-module-resolver/esm-test.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,16 @@
import { createResolve} from "./esm.js";
import { createResolve } from "./esm.js";

export const resolve = createResolve("/build/testing/packages");

// export async function getFormat(url: string, context, defaultGetFormat) {

// // we force node to understand and load the executable mocha as a commonjs module
// if (/bin\/mocha$/i.test(url)) {
// return {
// format: "commonjs",
// };
// }

// // Defer to Node.js for all other URLs.
// return defaultGetFormat(url, context, defaultGetFormat);
// }
19 changes: 9 additions & 10 deletions tools/local-module-resolver/esm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,19 @@ const cache = new Map<string, ResolvedValue>();

export interface ResolvedValue {
url: string;
format?: "module" | "commonjs";
format?: "module";
}

export interface ResolveContext {
conditions?: [];
parentUrl?: string | undefined;
}

export function createResolve(innerPath: string): (specifier: string, context: ResolveContext, defaultResolve: Function) => Promise<ResolvedValue> {
export interface ResolverFunc {
(specifier: string, context: ResolveContext, defaultResolve: Function): Promise<ResolvedValue>;
}

export function createResolve(innerPath: string): ResolverFunc {

return async function (specifier: string, context: ResolveContext, defaultResolve: Function): Promise<ResolvedValue> {

Expand Down Expand Up @@ -66,17 +70,12 @@ export function createResolve(innerPath: string): (specifier: string, context: R
return resolved;
}

// if (specifier.indexOf("_mocha") > -1) {
// return {
// url: specifier,
// format: "commonjs",
// };
// }

if (specifier.indexOf("settings.js") > -1 && /^[a-z]:[\\|/]/i.test(specifier) && isWin32) {
specifier = "file://" + specifier;
log(`patching file path for win32: ${specifier}`);
log(`patching settings.js import path for win32: ${specifier}`);
}



// Defer to Node.js for all other specifiers.
return defaultResolve(specifier, context, defaultResolve);
Expand Down

0 comments on commit 448310a

Please sign in to comment.