diff --git a/extension.bundle.ts b/extension.bundle.ts index 9e387162c..6d58c822b 100644 --- a/extension.bundle.ts +++ b/extension.bundle.ts @@ -15,10 +15,12 @@ * The tests are not packaged with the webpack bundle and therefore only have access to code exported from this file. * * The only non-test source files the .test.ts files should import is '../extension.bundle.ts'. - * At design-time the test sources are in /test, so '../extension.bundle.ts' will point the ts compiler to this Typescript file (/extension.bundle.ts). - * At runtime asdfg the tests live in /dist/test, so '../extension.bundle.ts' will pick up the main webpacked bundle at /dist/extension.bundle.js. + * At design-time and when running tests without webpack, the test sources are in /test, so '../extension.bundle.ts' will + * point the ts compiler to this Typescript file (/extension.bundle.ts). + * When running tests in webpack, the test sources live in /dist/test, so '../extension.bundle.ts' will pick up the main + * webpacked bundle at /dist/extension.bundle.js. */ -console.warn("==================================== extension.bundle.ts ===================================="); +//asdfg console.warn("==================================== extension.bundle.ts ===================================="); import * as TLE from "./src/language/expressions/TLE"; import * as Json from "./src/language/json/JSON"; diff --git a/gulpfile.ts b/gulpfile.ts index 8518ac742..72a3aebc5 100644 --- a/gulpfile.ts +++ b/gulpfile.ts @@ -14,12 +14,12 @@ import * as os from 'os'; import * as path from 'path'; import * as process from 'process'; import * as recursiveReadDir from 'recursive-readdir'; +import * as rimraf from 'rimraf'; import * as shelljs from 'shelljs'; import { gulp_webpack } from 'vscode-azureextensiondev'; import { DEFAULT_TESTCASE_TIMEOUT_MS, langServerDotnetVersion, languageServerFolderName } from './common'; import { getTempFilePath } from './test/support/getTempFilePath'; -import rimraf = require('rimraf'); const filesAndFoldersToPackage: string[] = [ // NOTE: License.txt and languageServer folder are handled separately so should not be in this list @@ -130,7 +130,7 @@ async function pretest(): Promise { if (result.error) { process.exit(1); } - fse.removeSync(path.join(__dirname, 'out', 'extension.bundle.js')); + //asdfg fse.removeSync(path.join(__dirname, 'out', 'extension.bundle.js')); //asdfg? // result = cp.spawnSync('node', ['./out/test/runTest.js'], { encoding: "utf-8", stdio: 'inherit', env, shell: true }); diff --git a/package.json b/package.json index 2c2774d05..5d847eab6 100644 --- a/package.json +++ b/package.json @@ -624,6 +624,7 @@ "$asdfg.pretest.should-be-release": "npm run pretest-release", "pretest-release": "npm run webpack-prod && gulp preTest", "pretest-dev": "npm run webpack && gulp preTest", + "$test.comment": "Runs tests from the webpacked extension. If you want to run tests from the source code directly, run from without vscode.", "test": "node ./dist/test/runTest.js", "all": "npm i && npm test && npm run lint", "webpack": "gulp webpack-dev", diff --git a/src/extension.ts b/src/extension.ts index 2c341f751..399f93f11 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -4,8 +4,6 @@ *--------------------------------------------------------------------------------------------*/ // tslint:disable:promise-function-async max-line-length // Grandfathered in -console.trace("======================================================== extension.ts"); - // CONSIDER: Refactor this file import * as path from 'path'; import * as vscode from "vscode"; diff --git a/src/extensionVariables.ts b/src/extensionVariables.ts index 3cfd93685..9741f22bc 100644 --- a/src/extensionVariables.ts +++ b/src/extensionVariables.ts @@ -3,8 +3,6 @@ * Licensed under the MIT License. See License.md in the project root for license information. *--------------------------------------------------------------------------------------------*/ -console.trace("======================================================== extensionVariables.ts"); - var stack = new Error().stack; console.log( stack ); diff --git a/test/index.ts b/test/index.ts index 1901afeec..120e7425d 100644 --- a/test/index.ts +++ b/test/index.ts @@ -3,13 +3,14 @@ * Licensed under the MIT License. See LICENSE.md in the project root for license information. *--------------------------------------------------------------------------------------------*/ -// This is the "test runner script" (https://code.visualstudio.com/api/working-with-extensions/testing-extension#advanced-setup-your-own-runner) +// This is our custom "test runner script" (https://code.visualstudio.com/api/working-with-extensions/testing-extension#advanced-setup-your-own-runner) import * as glob from 'glob-promise'; import * as Mocha from 'mocha'; import * as path from 'path'; -console.warn("==================================== index.ts ===================================="); +export const isWebpack: boolean = !!/^(false|0)?$/i.test(process.env.AZCODE_ARM_IGNORE_BUNDLE ?? ''); + // tslint:disable-next-line: export-name export async function run(): Promise { console.log("asdfg11"); @@ -61,3 +62,22 @@ function addEnvVarsToMochaOptions(options: Mocha.MochaOptions): void { } } } + +if (isWebpack) { + const originalRequire = module.constructor.prototype.require; + module.constructor.prototype.require = function (path: string) { + testPath(path); + try { + var path = require.resolve(path); + testPath(path); + } catch (e) { + } + return originalRequire.apply(this, arguments); + + function testPath(path: string): void { + if (/vscode-azurearmtools[/\\]out[/\\]/.test(path)) { + throw new Error("Trying to run code outside of the webpack bundle: " + path + ". See comments in extension.bundle.ts for more information."); + } + } + } +}