Skip to content

Commit 8244259

Browse files
Merge pull request #34 from oslabs-beta/AL/CR/LK-Jest_testing
AL/CR/LK - jest testing
2 parents 2da4e37 + 54d06ad commit 8244259

23 files changed

+7028
-3019
lines changed

.vscode-test.js

Lines changed: 0 additions & 9 deletions
This file was deleted.

babel.config.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module.exports = {
2+
presets: [
3+
['@babel/preset-env', {targets: {node: 'current'}}],
4+
'@babel/preset-typescript',
5+
],
6+
};

jest.config.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
const path = require('path');
2+
3+
module.exports = {
4+
preset: "ts-jest",
5+
testEnvironment: "node",
6+
preset: "ts-jest/presets/default-esm",
7+
globals: {
8+
"ts-jest": {
9+
useESM: true,
10+
},
11+
},
12+
moduleNameMapper: {
13+
vscode: path.join(__dirname, 'src', 'test', 'vscode.js')
14+
},
15+
testMatch: ['**/test/**/*.js', '**/?(*.)+(spec|test).js'],
16+
modulePathIgnorePatterns: ["node_modules"]
17+
};

package-lock.json

Lines changed: 6789 additions & 2894 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,13 @@
7171
"lint": "eslint .",
7272
"pretest": "npm run lint",
7373
"test": "node ./build/src/test/runTest.js",
74-
"test1": "vscode-test",
7574
"dev": "webpack --watch",
7675
"webpack": "webpack"
7776
},
7877
"devDependencies": {
78+
"@babel/preset-typescript": "^7.23.3",
7979
"@types/glob": "^8.1.0",
80-
"@types/mocha": "^10.0.3",
80+
"@types/jest": "^29.5.11",
8181
"@types/node": "18.x",
8282
"@types/react": "^18.2.45",
8383
"@types/react-dom": "^18.2.18",
@@ -86,10 +86,12 @@
8686
"@vscode/test-electron": "^2.3.8",
8787
"eslint": "^8.54.0",
8888
"glob": "^10.3.10",
89-
"mocha": "^10.2.0",
89+
"jest": "^29.7.0",
90+
"jest-environment-node": "^29.7.0",
9091
"postcss-loader": "^7.3.3",
9192
"postcss-preset-env": "^9.3.0",
9293
"tailwindcss": "^3.3.6",
94+
"ts-jest": "^29.1.2",
9395
"typescript": "^5.3.3",
9496
"webpack-cli": "^5.1.4"
9597
},

src/extension.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import { Tree } from './types/tree';
66
let tree: Parser | undefined = undefined;
77
let panel: vscode.WebviewPanel | undefined = undefined
88

9-
109
// This method is called when your extension is activated
1110
// Your extension is activated the very first time the command is executed
1211
function activate(context: vscode.ExtensionContext) {

src/panel.ts

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ export function createPanel(context: vscode.ExtensionContext, data: Tree, column
1010
panel = vscode.window.createWebviewPanel(
1111
'reactLabyrinth',
1212
'React Labyrinth',
13-
1413
// create one new tab
1514
vscode.ViewColumn.One,
1615
{
@@ -19,23 +18,18 @@ export function createPanel(context: vscode.ExtensionContext, data: Tree, column
1918
}
2019
);
2120

22-
2321
// Set the icon logo of extension webview
2422
panel.iconPath = vscode.Uri.joinPath(context.extensionUri, 'media', 'favicon.ico');
2523

26-
2724
// Set URI to be the path to bundle
2825
const bundlePath: vscode.Uri = vscode.Uri.joinPath(context.extensionUri, 'build', 'bundle.js');
2926

30-
3127
// set webview URI to pass into html script
3228
const bundleURI: vscode.Uri = panel.webview.asWebviewUri(bundlePath);
3329

34-
3530
// render html of webview here
3631
panel.webview.html = createWebviewHTML(bundleURI, data);
3732

38-
3933
// Sends data to Flow.tsx to be displayed after parsed data is received
4034
panel.webview.onDidReceiveMessage(
4135
async (msg: any) => {
@@ -51,7 +45,6 @@ export function createPanel(context: vscode.ExtensionContext, data: Tree, column
5145
settings: vscode.workspace.getConfiguration('reactLabyrinth')
5246
});
5347
break;
54-
5548
}
5649
},
5750
undefined,
@@ -61,12 +54,9 @@ export function createPanel(context: vscode.ExtensionContext, data: Tree, column
6154
return panel
6255
};
6356

64-
65-
6657
// getNonce generates a new random string each time ext is used to prevent external injection of foreign code into the html
6758
const nonce: string = getNonce();
6859

69-
7060
// function to create the HTML page for webview
7161
function createWebviewHTML(URI: vscode.Uri, initialData: Tree) : string {
7262
return (

src/test/runTest.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import * as path from 'path';
2-
32
import { runTests } from '@vscode/test-electron';
43

54
async function main() {
@@ -19,7 +18,11 @@ async function main() {
1918
console.log('inside try block after second var declare');
2019

2120
// Download VS Code, unzip it and run the integration test
22-
await runTests({ extensionDevelopmentPath, extensionTestsPath });
21+
await runTests({
22+
version: "1.85.1",
23+
extensionDevelopmentPath,
24+
extensionTestsPath
25+
});
2326
} catch (err) {
2427
console.error('Failed to run tests', err);
2528
process.exit(1);

src/test/suite/extension.test.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
1-
import * as assert from 'assert'
2-
31
// You can import and use all API from the 'vscode' module
42
// as well as import your extension to test it
53
import * as vscode from 'vscode'
64
// const myExtension = require('../extension');
75

8-
suite('Extension Test Suite', () => {
9-
vscode.window.showInformationMessage('Start all tests.');
6+
// we can either use test() or it() -- matter of style for team/project convention
7+
8+
describe('Extension Test Suite', () => {
9+
// beforeEach(() => {
10+
// vscode.window.showInformationMessage('Start all tests.');
11+
// });
1012

11-
test('Sample test', () => {
12-
assert.strictEqual(-1, [1, 2, 3].indexOf(5)); // false
13-
assert.strictEqual(-1, [1, 2, 3].indexOf(0));
14-
assert.strictEqual(0, [1, 2, 3].indexOf(1)); // true
13+
it('Sample test', () => {
14+
expect([1, 2, 3].indexOf(5)).toBe(-1);
15+
expect([1, 2, 3].indexOf(0)).toBe(-1);
16+
expect([1, 2, 3].indexOf(1)).toBe(0);
1517
});
1618
});

src/test/suite/index.ts

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,34 @@
11
import * as path from 'path';
2-
import * as Mocha from 'mocha';
32
import { glob } from 'glob';
3+
import * as jest from 'jest';
44

55
export async function run(): Promise<void> {
6-
// Create the mocha test
7-
const mocha = new Mocha.default({
8-
ui: 'tdd',
9-
color: true
10-
});
6+
try {
7+
console.log('inside try block of index.ts');
118

12-
const testsRoot = path.resolve(__dirname, '..');
13-
const files = await glob('**/**.test.js', { cwd: testsRoot });
9+
const testsRoot = path.resolve(__dirname, '..');
10+
const files = await glob('**/**.test.js', { cwd: testsRoot });
11+
12+
if (files.length === 0) {
13+
console.warn('No test files found');
14+
return;
15+
}
1416

15-
// Add files to the test suite
16-
files.forEach(f => mocha.addFile(path.resolve(testsRoot, f)));
17+
console.log('test files: ', files);
1718

18-
try {
19-
return new Promise((c, e) => {
20-
// Run the mocha test
21-
mocha.run(failures => {
22-
if (failures > 0) {
23-
e(new Error(`${failures} tests failed.`));
24-
} else {
25-
c();
26-
}
27-
});
19+
return new Promise(async (c, e) => {
20+
try {
21+
console.log('inside promise block of index.ts before await ')
22+
await jest.run([...files]);
23+
console.log('inside promise block of index.ts after await')
24+
c();
25+
console.log('inside promise block of index.ts after c()')
26+
} catch (err) {
27+
console.error(err);
28+
e(err);
29+
}
2830
});
2931
} catch (err) {
3032
console.error(err);
3133
}
32-
}
33-
34+
}

0 commit comments

Comments
 (0)