You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm developing an extension for VS Code and writing unit tests against my objects used by that extension. Those tests run successfully from within VS Code. However, I also run them as part of my CI build and I do that via gulp. I have a gulp task that uses "gulp mocha" to run the tests. Those tests run successfully via gulp until I bring in a class that, anywhere in its transitive closure of module references, pulls in 'vscode'.
My gulp output is below:
[14:00:48] Starting 'test'...
[14:00:48] { [Error: Cannot find module 'vscode']
code: 'MODULE_NOT_FOUND',
name: 'Error',
message: 'Cannot find module \'vscode\'',
stack: 'Error: Cannot find module \'vscode\'\n
at Function.Module._resolveFilename (module.js:325:15)\n
at Function.Module._load (module.js:276:25)\n
at Module.require (module.js:353:17)\n
at require (internal/module.js:12:17)\n
at Object.<anonymous> (C:\\vsts- vscode.repro.0\\out\\src\\myobject.js:2:18)\n
at Module._compile (module.js:397:26)\n
at Object.Module._extensions..js (module.js:404:10)\n
at Module.load (module.js:343:32)\n
at Function.Module._load (module.js:300:12)\n
at Module.require (module.js:353:17)',
showStack: true,
showProperties: true,
plugin: 'gulp-mocha' }
[14:00:48] 'test' errored after 45 ms
[14:00:48] Error in plugin 'gulp-mocha'
Message:
Cannot find module 'vscode'
Details:
code: MODULE_NOT_FOUND
Stack:
Error: Cannot find module 'vscode'
at Function.Module._resolveFilename (module.js:325:15)
at Function.Module._load (module.js:276:25)
at Module.require (module.js:353:17)
at require (internal/module.js:12:17)
at Object.<anonymous> (C:\vsts-vscode.repro.0\out\src\myobject.js:2:18)
at Module._compile (module.js:397:26)
at Object.Module._extensions..js (module.js:404:10)
at Module.load (module.js:343:32)
at Function.Module._load (module.js:300:12)
at Module.require (module.js:353:17)
In the call stack, there's a reference to out\src\myobject.js:2:18. At that location is this statement:
const vscode_1 = require("vscode");
In my typescript source, that is:
import { workspace } from "vscode";
If I remove the code that uses workspace, the tests go back to running successfully.
After going through the documentation regarding node.js module resolution, I can understand why I get MODULE_NOT_FOUND. Since "vscode" isn't a core module and isn't a relative reference (".", "/", "../"), node will look for the package.json file. Assuming it finds it (procmon tells me it does), it looks for a "main" field. I'm guessing, at this point, it doesn't find the "main" field and fails the resolution.
Presumably, when running the tests in VS Code, the resolution also includes locating the typings file and is thus successful.
What I can't figure out is what I might do to resolve the reference to "vscode" when I run tests via gulp.
Any thoughts?
myobject.ts
import { workspace } from "vscode";
export class MyObject {
constructor() {
let configuration = workspace.getConfiguration();
}
}
myobject.test.ts
import { MyObject } from "../src/myobject";
var assert = require("chai").assert;
describe("MyObject", function() {
it("should verify MyObject", function() {
new MyObject();
});
});
Hi @weinand. I've made sure that step gets run so the proper version of vscode gets installed.
> node ./node_modules/vscode/bin/install
Detected VS Code engine version: ^0.10.7
Found minimal version that qualifies engine range: 0.10.8
Fetching vscode.d.ts from: https://raw.githubusercontent.com/Microsoft/vscode/0.10.8/src/vs/vscode.d.ts
vscode.d.ts successfully installed!
I can provide a small-ish repro that will run successfully within VS Code but a minimal gulpfile.js will result in the missing module error (it's about an 11KB zip file).
Note that vscode is not a real node_module. You can only present in the context of VSCode.
We have a special test runner that first starts VSCode and then runs your test inside the extension host.
I'm developing an extension for VS Code and writing unit tests against my objects used by that extension. Those tests run successfully from within VS Code. However, I also run them as part of my CI build and I do that via gulp. I have a gulp task that uses "gulp mocha" to run the tests. Those tests run successfully via gulp until I bring in a class that, anywhere in its transitive closure of module references, pulls in 'vscode'.
My gulp output is below:
In the call stack, there's a reference to out\src\myobject.js:2:18. At that location is this statement:
In my typescript source, that is:
If I remove the code that uses workspace, the tests go back to running successfully.
After going through the documentation regarding node.js module resolution, I can understand why I get MODULE_NOT_FOUND. Since "vscode" isn't a core module and isn't a relative reference (".", "/", "../"), node will look for the package.json file. Assuming it finds it (procmon tells me it does), it looks for a "main" field. I'm guessing, at this point, it doesn't find the "main" field and fails the resolution.
Presumably, when running the tests in VS Code, the resolution also includes locating the typings file and is thus successful.
What I can't figure out is what I might do to resolve the reference to "vscode" when I run tests via gulp.
Any thoughts?
myobject.ts
myobject.test.ts
package.json (scripts and dependencies)
The text was updated successfully, but these errors were encountered: