Skip to content

Commit

Permalink
work
Browse files Browse the repository at this point in the history
  • Loading branch information
StephenWeatherford committed Jul 22, 2024
1 parent b1e8636 commit 9b52dc9
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 11 deletions.
8 changes: 5 additions & 3 deletions extension.bundle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 <root>/test, so '../extension.bundle.ts' will point the ts compiler to this Typescript file (<root>/extension.bundle.ts).
* At runtime asdfg the tests live in <root>/dist/test, so '../extension.bundle.ts' will pick up the main webpacked bundle at <root>/dist/extension.bundle.js.
* At design-time and when running tests without webpack, the test sources are in <root>/test, so '../extension.bundle.ts' will
* point the ts compiler to this Typescript file (<root>/extension.bundle.ts).
* When running tests in webpack, the test sources live in <root>/dist/test, so '../extension.bundle.ts' will pick up the main
* webpacked bundle at <root>/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";
Expand Down
4 changes: 2 additions & 2 deletions gulpfile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -130,7 +130,7 @@ async function pretest(): Promise<void> {
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 });
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 0 additions & 2 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
2 changes: 0 additions & 2 deletions src/extensionVariables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 );

Expand Down
24 changes: 22 additions & 2 deletions test/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> {
console.log("asdfg11");
Expand Down Expand Up @@ -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.");
}
}
}
}

0 comments on commit 9b52dc9

Please sign in to comment.