Skip to content

Commit fcf3c37

Browse files
committed
✅ add test script
can't use it in ci
1 parent f8fdd66 commit fcf3c37

File tree

3 files changed

+93
-8
lines changed

3 files changed

+93
-8
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@
286286
"pretest": "tsc -p ./",
287287
"test": "node ./dist/test/runTest.js",
288288
"pretest-web": "yarn run compile",
289-
"test-web": "vscode-test-web --browserType=chromium --extensionDevelopmentPath=. --extensionTestsPath=dist/web/test/suite/index.js",
289+
"test-web": "vscode-test-web --browserType=chromium --extensionDevelopmentPath=. --extensionTestsPath=dist/web/test/suite/index.js --extensionPath=../vscode-dosbox ./samples",
290290
"run-in-browser": "vscode-test-web --browserType=chromium --extensionDevelopmentPath=. .",
291291
"lint": "eslint src --ext ts",
292292
"lint-fix": "eslint src --ext ts --fix",

src/web/test/suite/ASM.test.ts

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
2+
import * as assert from 'assert';
3+
4+
// You can import and use all API from the 'vscode' module
5+
// as well as import your extension to test it
6+
import * as vscode from 'vscode';
7+
import { AsmResult } from '../../../ASM/main';
8+
import { DIAGCODE } from '../../../diagnose/main';
9+
import { DosEmulatorType, Assembler } from '../../../utils/configuration';
10+
11+
// import * as myExtension from '../../extension';
12+
const folders = vscode.workspace.workspaceFolders;
13+
if (folders === undefined) {
14+
throw new Error();
15+
}
16+
const samplesUri = folders[0].uri;
17+
18+
suite('Extension Test Suite', function () {
19+
vscode.window.showInformationMessage('Start all tests.');
20+
const MASMorTASM = [
21+
Assembler['MASM-v5.00'],
22+
Assembler['MASM-v6.11'],
23+
Assembler.TASM,
24+
];
25+
const emulator: DosEmulatorType[] = [
26+
DosEmulatorType.jsdos,
27+
];
28+
29+
const filelist: [string, number][] = [
30+
['1.asm', 0],
31+
['3中文路径hasError.asm', 1],
32+
// ['2.asm', DIAGCODE.ok],
33+
];
34+
35+
const args: [string, DIAGCODE, DosEmulatorType, Assembler][] = [];
36+
for (const file of filelist) {
37+
for (const emu of emulator) {
38+
for (const asm of MASMorTASM) {
39+
args.push([file[0], file[1], emu, asm]);
40+
}
41+
}
42+
}
43+
44+
this.beforeEach(async function () {
45+
await vscode.commands.executeCommand('workbench.action.closeAllEditors');
46+
});
47+
48+
shuffle(args).forEach((val) => { testAsmCode(...val); });
49+
});
50+
51+
function testAsmCode(file: string, shouldErr: number, emu: DosEmulatorType, asm: Assembler): void {
52+
test(`test file ${file} in ${emu} use ${asm} want should ${shouldErr} error`,
53+
async function () {
54+
this.timeout('60s');
55+
this.slow('20s');
56+
//skip azure pipeline test for this condition
57+
if (file === '3中文路径hasError.asm' && emu === DosEmulatorType.msdos && asm === Assembler.MASM && !process.env.LANG?.includes('zh_CN')) {
58+
this.skip();
59+
}
60+
61+
//open test file. NOTE: the extension will be activated when open .asm file
62+
const samplefile = vscode.Uri.joinPath(samplesUri, file);
63+
64+
//update settings
65+
await vscode.workspace.getConfiguration('masmtasm').update("dosbox.run", "exit");
66+
await vscode.workspace.getConfiguration('masmtasm').update("ASM.emulator", emu);
67+
await vscode.workspace.getConfiguration('masmtasm').update("ASM.assembler", asm);
68+
69+
//assert the extension activated and command contributed
70+
const vscodecmds = await vscode.commands.getCommands(true);
71+
const cmd = 'masm-tasm.runASM';
72+
if (!vscodecmds.includes(cmd)) {
73+
await vscode.extensions.getExtension('xsro.masm-tasm')?.activate();
74+
}
75+
const vscodecmds2 = await vscode.commands.getCommands(true);
76+
assert.ok(vscodecmds2.includes(cmd));
77+
78+
//assert message processed
79+
const _result = await vscode.commands.executeCommand(cmd, samplefile);
80+
const { message, error } = _result as AsmResult;
81+
assert.strictEqual(error, shouldErr, message);
82+
});
83+
}
84+
85+
function shuffle<T>(arr: T[]): T[] {
86+
for (let i = 1; i < arr.length; i++) {
87+
const random = Math.floor(Math.random() * (i + 1));
88+
[arr[i], arr[random]] = [arr[random], arr[i]];
89+
}
90+
return arr;
91+
}

webpack.config.js

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ const path = require('path');
1313
/** @type WebpackConfig */
1414
const config = {
1515
target: 'node', // vscode extensions run in a Node.js-context 📖 -> https://webpack.js.org/configuration/node/
16-
1716
entry: './src/extension.ts', // the entry point of this extension, 📖 -> https://webpack.js.org/configuration/entry-context/
1817
output: { // the bundle is stored in the 'dist' folder (check package.json), 📖 -> https://webpack.js.org/configuration/output/
1918
path: path.resolve(__dirname, 'dist'),
@@ -27,7 +26,6 @@ const config = {
2726
devtool: 'source-map',
2827
externals: {
2928
vscode: "commonjs vscode", // the vscode-module is created on-the-fly and must be excluded. Add other modules that cannot be webpack'ed, 📖 -> https://webpack.js.org/configuration/externals/
30-
emulators: "commonjs emulators",
3129
},
3230
resolve: { // support reading TypeScript and JavaScript files, 📖 -> https://github.com/TypeStrong/ts-loader
3331
extensions: ['.ts', '.js'],
@@ -49,10 +47,7 @@ const config = {
4947
}]
5048
},
5149
optimization: {
52-
minimize: process.argv.includes('--mode production')
53-
},
54-
stats: {
55-
warnings: false
50+
minimize: true
5651
}
5752
};
5853

@@ -84,7 +79,6 @@ const webExtensionConfig = {
8479
// for the list of Node.js core module polyfills.
8580
assert: require.resolve('assert'),
8681
path: require.resolve('path-browserify'),
87-
"node-fetch": false
8882
},
8983
},
9084
module: {

0 commit comments

Comments
 (0)