Skip to content

Commit 1b4ce2b

Browse files
committed
Update to try and make Webpack work
1 parent 346ab17 commit 1b4ce2b

11 files changed

+149
-77
lines changed

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
out
1+
dist
22
node_modules
33
.vscode-test/
4+
.vscode-test-web/
45
*.vsix
56
*.vsix.zip

.vscode/launch.json

+45-7
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"version": "0.2.0",
77
"configurations": [
88
{
9-
"name": "Run Extension",
9+
"name": "Launch Extension",
1010
"type": "extensionHost",
1111
"request": "launch",
1212
"runtimeExecutable": "${execPath}",
@@ -15,25 +15,63 @@
1515
"--disable-extensions",
1616
"--extensionDevelopmentPath=${workspaceFolder}"
1717
],
18+
"stopOnEntry": false,
19+
"sourceMaps": true,
1820
"outFiles": [
19-
"${workspaceFolder}/out/**/*.js"
21+
"${workspaceFolder}/dist/**/*.js"
2022
],
21-
"preLaunchTask": "${defaultBuildTask}"
23+
"preLaunchTask": "npm: watch"
2224
},
2325
{
24-
"name": "Extension Tests",
26+
"name": "Launch Tests",
2527
"type": "extensionHost",
2628
"request": "launch",
2729
"runtimeExecutable": "${execPath}",
2830
"args": [
2931
"--disable-extensions",
3032
"--extensionDevelopmentPath=${workspaceFolder}",
31-
"--extensionTestsPath=${workspaceFolder}/out/test/suite/index"
33+
"--extensionTestsPath=${workspaceFolder}/dist/test/suite/index-node"
3234
],
35+
"stopOnEntry": false,
36+
"sourceMaps": true,
3337
"outFiles": [
34-
"${workspaceFolder}/out/test/**/*.js"
38+
"${workspaceFolder}/dist/**/*.js"
3539
],
36-
"preLaunchTask": "${defaultBuildTask}"
40+
"preLaunchTask": "npm: watch"
41+
},
42+
{
43+
"name": "Run Web Extension in VS Code",
44+
"type": "pwa-extensionHost",
45+
"debugWebWorkerHost": true,
46+
"request": "launch",
47+
"args": [
48+
"${workspaceFolder}/src/test/fixtures",
49+
"--disable-extensions",
50+
"--extensionDevelopmentPath=${workspaceFolder}",
51+
"--extensionDevelopmentKind=web"
52+
],
53+
"outFiles": [
54+
"${workspaceFolder}/dist/**/*.js"
55+
],
56+
"preLaunchTask": "npm: watch"
57+
},
58+
{
59+
"name": "Extension Tests in VS Code",
60+
"type": "extensionHost",
61+
"debugWebWorkerHost": true,
62+
"request": "launch",
63+
"args": [
64+
"${workspaceFolder}/src/test/fixtures",
65+
"--disable-extensions",
66+
"--extensionDevelopmentPath=${workspaceFolder}",
67+
"--extensionDevelopmentKind=web",
68+
"--extensionTestsPath=${workspaceFolder}/dist/test/suite/index-web"
69+
],
70+
"sourceMaps": true,
71+
"outFiles": [
72+
"${workspaceFolder}/dist/**/*.js"
73+
],
74+
"preLaunchTask": "npm: watch"
3775
}
3876
]
3977
}

.vscodeignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
.vscode/**
33
.vscode-test/**
44
images/**
5-
out/test/**
5+
dist/test/**
66
src/**
77
.gitignore
88
vsc-extension-quickstart.md

package.json

+10-6
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@
2727
"onCommand:snippet-copy.copySnippet",
2828
"onCommand:snippet-copy.copySnippetAsMarkdownCodeBlock"
2929
],
30-
"main": "./out/extension.js",
30+
"main": "./dist/extension-node.js",
31+
"browser": "./dist/extension-web.js",
3132
"contributes": {
3233
"commands": [
3334
{
@@ -101,12 +102,15 @@
101102
}
102103
},
103104
"scripts": {
104-
"vscode:prepublish": "npm run compile",
105-
"compile": "tsc -p ./",
105+
"vscode:prepublish": "npm run package",
106106
"lint": "eslint src --ext ts",
107-
"watch": "tsc -watch -p ./",
108-
"pretest": "npm run compile && npm run lint",
109-
"test": "node ./out/test/runTest.js"
107+
"compile": "webpack",
108+
"watch": "webpack --watch",
109+
"pretest": "npm run lint && npm run compile",
110+
"test": "npm run test-node && npm run test-web",
111+
"test-node": "node ./dist/test/runTest.js",
112+
"test-web": "vscode-test-web ./src/test/fixtures --browserType=chromium --extensionDevelopmentPath=. --extensionTestsPath=./dist/test/suite/index-web.js",
113+
"package": "webpack --mode production --devtool hidden-source-map"
110114
},
111115
"devDependencies": {
112116
"@types/glob": "^7.2.0",

src/test/runTest.ts

+8-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1+
import { runTests } from '@vscode/test-electron';
12
import * as path from 'path';
2-
import { runTests } from 'vscode-test';
33

44

55
async function main() {
@@ -10,10 +10,15 @@ async function main() {
1010

1111
// The path to test runner
1212
// Passed to --extensionTestsPath
13-
const extensionTestsPath = path.resolve(__dirname, './suite/index');
13+
const extensionTestsPath = path.resolve(__dirname, './suite/index-node');
14+
15+
const launchArgs = [
16+
path.resolve(__dirname, './fixtures'),
17+
'--disable-extensions'
18+
];
1419

1520
// Download VS Code, unzip it and run the integration test
16-
await runTests({ extensionDevelopmentPath, extensionTestsPath });
21+
await runTests({ extensionDevelopmentPath, extensionTestsPath, launchArgs });
1722
} catch (err) {
1823
console.error('Failed to run tests');
1924
process.exit(1);

src/test/suite/index.ts src/test/suite/index-node.ts

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import * as glob from 'glob';
22
import * as Mocha from 'mocha';
33
import * as path from 'path';
44

5+
require.context('./lib', true, /\.test\.ts$/);
6+
57
export function run(): Promise<void> {
68
// Create the mocha test
79
const mocha = new Mocha({

src/test/suite/index-web.ts

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
require('mocha/mocha'); // import the mocha web build
2+
3+
export function run(): Promise<void> {
4+
5+
return new Promise((c, e) => {
6+
mocha.setup({
7+
ui: 'bdd',
8+
reporter: undefined
9+
});
10+
11+
// bundles all files in the current directory matching `*.test`
12+
const importAll = (r: __WebpackModuleApi.RequireContext) => r.keys().forEach(r);
13+
importAll(require.context('.', true, /\.test$/));
14+
15+
try {
16+
// Run the mocha test
17+
mocha.run(failures => {
18+
if (failures > 0) {
19+
e(new Error(`${failures} tests failed.`));
20+
} else {
21+
c();
22+
}
23+
});
24+
} catch (err) {
25+
console.error(err);
26+
e(err);
27+
}
28+
});
29+
}
+23-30
Original file line numberDiff line numberDiff line change
@@ -1,86 +1,79 @@
11
import * as assert from 'assert';
2-
import * as path from 'path';
32
import * as vscode from 'vscode';
43
import { Range, TextDocument } from 'vscode';
54
import { adjustedRangeWithMinimumIndentation, contentOfLinesWithAdjustedIndentation, endOfLineCharacter, linesForIndexes, minimumIndentationForLineIndexes } from '../../../lib/documentHelpers';
65

7-
8-
const fixturesPath = '/../../../../src/test/fixtures/';
9-
const uri = vscode.Uri.file(
10-
path.join(__dirname + fixturesPath + 'javascript-example.js')
11-
);
6+
const fixtureUri = (fileName: string) => {
7+
const workspaceFolder = vscode.workspace.workspaceFolders![0];
8+
return vscode.Uri.joinPath(workspaceFolder.uri, fileName);
9+
};
1210

1311
describe('Document Helpers', function () {
1412
let document: TextDocument;
1513

1614
before(async () => {
15+
const uri = fixtureUri('javascript-example.js');
1716
document = await vscode.workspace.openTextDocument(uri);
1817
});
1918

2019
context('linesForIndexes', () => {
2120
it('returns the correct lines', () => {
2221
const lines = linesForIndexes(document, [0, 1]);
23-
assert.equal(lines.length, 2);
24-
assert.equal(lines[0].lineNumber, 0);
25-
assert.equal(lines[0].text, 'class MyThing {');
26-
assert.equal(lines[1].lineNumber, 1);
27-
assert.equal(lines[1].text, ' doSomething(aValue) {');
22+
assert.strictEqual(lines.length, 2);
23+
assert.strictEqual(lines[0].lineNumber, 0);
24+
assert.strictEqual(lines[0].text, 'class MyThing {');
25+
assert.strictEqual(lines[1].lineNumber, 1);
26+
assert.strictEqual(lines[1].text, ' doSomething(aValue) {');
2827
});
2928
});
3029

3130
context('minimumIndentationLevelForLineIndexes', () => {
3231
it('calculates the correct minimum indentation level for a single line', () => {
33-
assert.equal(minimumIndentationForLineIndexes(document, [3]), 6);
32+
assert.strictEqual(minimumIndentationForLineIndexes(document, [3]), 6);
3433
});
3534

3635
it('calculates the correct minimum indentation level for multiple lines', () => {
37-
assert.equal(minimumIndentationForLineIndexes(document, [1, 2, 3]), 2);
36+
assert.strictEqual(minimumIndentationForLineIndexes(document, [1, 2, 3]), 2);
3837
});
3938

4039
it('calculates the correct minimum indentation level when lines contain an empty line', () => {
41-
assert.equal(minimumIndentationForLineIndexes(document, [11, 12, 13, 14]), 4);
40+
assert.strictEqual(minimumIndentationForLineIndexes(document, [11, 12, 13, 14]), 4);
4241
});
4342
});
4443

4544
context('contentOfLinesWithAdjustedIndentation', () => {
4645
it('returns multiline text with the indentation adjusted correctly', () => {
47-
assert.equal(contentOfLinesWithAdjustedIndentation(document, [2, 3, 4], 4), 'if (aValue) {\n console.log(`Doing something with ${aValue}!`);\n}');
46+
assert.strictEqual(contentOfLinesWithAdjustedIndentation(document, [2, 3, 4], 4), 'if (aValue) {\n console.log(`Doing something with ${aValue}!`);\n}');
4847
});
4948

5049
it('returns single line text with the indentation adjusted correctly', () => {
51-
assert.equal(contentOfLinesWithAdjustedIndentation(document, [3], 6), 'console.log(`Doing something with ${aValue}!`);');
50+
assert.strictEqual(contentOfLinesWithAdjustedIndentation(document, [3], 6), 'console.log(`Doing something with ${aValue}!`);');
5251
});
5352

5453
it('returns text with CRLF characters if file is using them', async () => {
55-
const uri = vscode.Uri.file(
56-
path.join(__dirname + fixturesPath + 'crlf-ruby-example.rb')
57-
);
58-
const crlfDocument = await vscode.workspace.openTextDocument(uri);
54+
const crlfDocument = await vscode.workspace.openTextDocument(fixtureUri('crlf-ruby-example.rb'));
5955

60-
assert.equal(contentOfLinesWithAdjustedIndentation(crlfDocument, [1, 2, 3], 2), 'def polish\r\n puts "Polishing"\r\nend');
56+
assert.strictEqual(contentOfLinesWithAdjustedIndentation(crlfDocument, [1, 2, 3], 2), 'def polish\r\n puts "Polishing"\r\nend');
6157
});
6258
});
6359

6460
context('adjustedRangeWithMinimumIndentation', () => {
6561
it('adjusts the range', () => {
6662
const adjustedRange = adjustedRangeWithMinimumIndentation(new Range(2, 0, 2, 17), 4);
67-
assert.equal(adjustedRange.start.line, 2);
68-
assert.equal(adjustedRange.start.character, 4);
69-
assert.equal(adjustedRange.end.line, 2);
70-
assert.equal(adjustedRange.end.character, 17);
63+
assert.strictEqual(adjustedRange.start.line, 2);
64+
assert.strictEqual(adjustedRange.start.character, 4);
65+
assert.strictEqual(adjustedRange.end.line, 2);
66+
assert.strictEqual(adjustedRange.end.character, 17);
7167
});
7268
});
7369

7470
context('endOfLineCharacter', () => {
7571
it('correctly returns LF', () => {
76-
assert.equal(endOfLineCharacter(document), '\n');
72+
assert.strictEqual(endOfLineCharacter(document), '\n');
7773
});
7874

7975
it('correctly returns CRLF', async () => {
80-
const uri = vscode.Uri.file(
81-
path.join(__dirname + fixturesPath + 'crlf-ruby-example.rb')
82-
);
83-
assert.equal(endOfLineCharacter(await vscode.workspace.openTextDocument(uri)), '\r\n');
76+
assert.strictEqual(endOfLineCharacter(await vscode.workspace.openTextDocument(fixtureUri('crlf-ruby-example.rb'))), '\r\n');
8477
});
8578
});
8679
});

src/test/suite/lib/selectionHelpers.test.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,19 @@ import { lineIndexesForSelection } from '../../../lib/selectionHelpers';
66
describe('Selection Helpers', function () {
77
context('calculateSelectionLineIndexes', () => {
88
it('calculates the correct line indexes from an empty selection', () => {
9-
assert.deepEqual([0], lineIndexesForSelection(new Selection(0, 0, 0, 0)));
9+
assert.deepStrictEqual([0], lineIndexesForSelection(new Selection(0, 0, 0, 0)));
1010
});
1111

1212
it('calculates the correct line indexes from a single line selection', () => {
13-
assert.deepEqual([1], lineIndexesForSelection(new Selection(1, 2, 1, 15)));
13+
assert.deepStrictEqual([1], lineIndexesForSelection(new Selection(1, 2, 1, 15)));
1414
});
1515

1616
it('calculates the correct line indexes from a multiline selection', () => {
17-
assert.deepEqual([1, 2, 3], lineIndexesForSelection(new Selection(1, 2, 3, 3)));
17+
assert.deepStrictEqual([1, 2, 3], lineIndexesForSelection(new Selection(1, 2, 3, 3)));
1818
});
1919

2020
it('calculates the correct line indexes from an reversed selection ', () => {
21-
assert.deepEqual([1, 2, 3], lineIndexesForSelection(new Selection(3, 0, 1, 0)));
21+
assert.deepStrictEqual([1, 2, 3], lineIndexesForSelection(new Selection(3, 0, 1, 0)));
2222
});
2323
});
2424
});

0 commit comments

Comments
 (0)