Skip to content

Commit

Permalink
Refactor the test code into a different folder and start a new test s…
Browse files Browse the repository at this point in the history
…uite
  • Loading branch information
tonybaloney committed Sep 30, 2022
1 parent 2410825 commit 042bd49
Show file tree
Hide file tree
Showing 15 changed files with 1,308 additions and 132 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@ jobs:
- run: npm ci
- run: npm run compile
- run: npm run lint
- run: npm run test
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"request": "launch",
"args": [
"--extensionDevelopmentPath=${workspaceFolder}",
"--extensionTestsPath=${workspaceFolder}/out/extension/test/suite/index"
"--extensionTestsPath=${workspaceFolder}/out/test/suite/index"
],
"outFiles": [
"${workspaceFolder}/out/test/**/*.js"
Expand Down
1,314 changes: 1,213 additions & 101 deletions package-lock.json

Large diffs are not rendered by default.

7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -176,16 +176,18 @@
"vscode:prepublish": "npm run compile",
"compile:panel": "webpack",
"compile:extension": "tsc -p ./tsconfig.extension.json",
"compile": "npm run compile:panel && npm run compile:extension",
"compile:test": "tsc -p ./tsconfig.test.json",
"compile": "npm run compile:panel && npm run compile:extension && npm run compile:test",
"watch": "tsc -watch -p ./tsconfig.extension.json",
"pretest": "npm run compile && npm run lint",
"lint": "eslint src --ext ts && prettier --check src",
"lint:fix": "eslint src --ext ts --fix && prettier --write src",
"test": "node ./out/extension/test/runTest.js"
"test": "node ./out/test/runTest.js"
},
"devDependencies": {
"@rbarilani/remove-source-map-url-webpack-plugin": "^1.1.0",
"@types/glob": "^7.1.3",
"@types/jsdom": "^20.0.0",
"@types/mocha": "^9.1.1",
"@types/node": "^18.0.0",
"@types/vscode": "^1.68.0",
Expand All @@ -194,6 +196,7 @@
"eslint": "^8.18.0",
"eslint-plugin-unused-imports": "^2.0.0",
"glob": "^8.0.3",
"jsdom": "^20.0.0",
"mocha": "^10.0.0",
"prettier": "^2.7.1",
"ts-loader": "^9.3.0",
Expand Down
12 changes: 0 additions & 12 deletions src/extension/test/suite/extension.test.js

This file was deleted.

15 changes: 0 additions & 15 deletions src/extension/test/suite/extension.test.ts

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
65 changes: 65 additions & 0 deletions src/test/suite/panel.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import * as assert from 'assert';

// You can import and use all API from the 'vscode' module
// as well as import your extension to test it
import * as vscode from 'vscode';
import { PetSize, PetType, PetColor } from '../../common/types';
import * as pets from '../../panel/pets';

import { JSDOM } from 'jsdom';

declare global {
namespace NodeJS {
interface Global {
document: Document;
window: Window;
navigator: Navigator;
}
}
}

const { window } = new JSDOM('<!doctype html><html><body></body></html>');
global.document = window.document;
global.window = global.document.defaultView;

suite('Pets Test Suite', () => {
vscode.window.showInformationMessage('Start all tests.');

test('Test pet collection', () => {
var collection = new pets.PetCollection();
const petImageEl = new HTMLImageElement();
const petDivEl = new HTMLDivElement();
const testPet = pets.createPet(
'cat',
petImageEl,
petDivEl,
PetSize.medium,
0,
0,
'testPet',
0,
'Jerry',
);
assert(testPet instanceof pets.Cat);
assert(testPet.emoji() === '🐱');
assert(testPet.name() === 'Jerry');

const testPetElement = new pets.PetElement(
petImageEl,
petDivEl,
testPet,
PetColor.brown,
PetType.cat,
);
assert(testPetElement.color === PetColor.brown);
assert(testPetElement.type === PetType.cat);

assert(collection.locate('Jerry') === undefined);

collection.push(testPetElement);
assert(collection.locate('Jerry') === testPetElement);

collection.remove('Jerry');
assert(collection.locate('Jerry') === undefined);
});
});
1 change: 1 addition & 0 deletions tsconfig.extension.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@
"node_modules",
".vscode-test",
"src/panel",
"src/test"
]
}
3 changes: 2 additions & 1 deletion tsconfig.panel.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"exclude": [
"node_modules",
".vscode-test",
"src/extension"
"src/extension",
"src/test"
]
}
20 changes: 20 additions & 0 deletions tsconfig.test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"compilerOptions": {
"module": "commonjs",
"target": "esnext",
"outDir": "out",
"lib": [
"es6", "DOM"
],
"sourceMap": true,
"rootDirs": ["panel", "common", "test", "extension"],
"strict": true /* enable all strict type-checking options */
/* Additional Checks */
// "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
// "noUnusedParameters": true, /* Report errors on unused parameters. */
},
"exclude": [
"node_modules",
]
}

0 comments on commit 042bd49

Please sign in to comment.