Skip to content

Commit

Permalink
Merge pull request #168 from tonybaloney/more_integration_testing
Browse files Browse the repository at this point in the history
  • Loading branch information
tonybaloney authored Oct 3, 2022
2 parents 0721c4c + cabfbff commit 9512416
Show file tree
Hide file tree
Showing 16 changed files with 3,866 additions and 362 deletions.
12 changes: 12 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,15 @@ jobs:
- run: npm ci
- run: npm run compile
- run: npm run lint
- name: Run unit and integration tests
uses: GabrielBB/[email protected]
with:
run: npm run test
- name: Run coverage
uses: GabrielBB/[email protected]
continue-on-error: true
with:
run: npm run test:coverage
# - uses: codecov/codecov-action@v3
# with:
# directory: ./coverage
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@ dist
node_modules
.vscode-test/
*.vsix
.build-out/
.build-out/
coverage/
.nyc_output/
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
4,064 changes: 3,734 additions & 330 deletions package-lock.json

Large diffs are not rendered by default.

28 changes: 26 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -176,16 +176,20 @@
"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",
"test:coverage": "nyc npm run test"
},
"devDependencies": {
"@istanbuljs/nyc-config-typescript": "^1.0.2",
"@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,13 +198,33 @@
"eslint": "^8.18.0",
"eslint-plugin-unused-imports": "^2.0.0",
"glob": "^8.0.3",
"jsdom": "^20.0.0",
"mocha": "^10.0.0",
"nyc": "^15.1.0",
"prettier": "^2.7.1",
"ts-loader": "^9.3.0",
"typescript": "^4.7.4",
"typescript-eslint": "^0.0.1-alpha.0",
"vscode-test": "^1.4.0",
"webpack": "^5.73.0",
"webpack-cli": "^4.10.0"
},
"nyc": {
"extends": "@istanbuljs/nyc-config-typescript",
"check-coverage": true,
"all": true,
"include": [
"src/**/!(*.test.*).[tj]s?(x)"
],
"exclude": [
"src/_tests_/**/*.*"
],
"reporter": [
"html",
"lcov",
"text",
"text-summary"
],
"report-dir": "coverage"
}
}
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.
2 changes: 2 additions & 0 deletions src/extension/test/suite/index.js → src/test/suite/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ export function run() {
const mocha = new Mocha({
ui: 'tdd',
color: true,
require: ['ts-node/register', 'source-map-support/register'],
recursive: true,
});
const testsRoot = path.resolve(__dirname, '..');
return new Promise((c, e) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export function run(): Promise<void> {
const mocha = new Mocha({
ui: 'tdd',
color: true,
require: ['ts-node/register', 'source-map-support/register'],
});

const testsRoot = path.resolve(__dirname, '..');
Expand Down
64 changes: 64 additions & 0 deletions src/test/suite/panel.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
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;
}
}
}

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

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

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

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

assert.strictEqual(collection.locate('Jerry'), undefined);

collection.push(testPetElement);
assert.strictEqual(collection.locate('Jerry'), testPetElement);

collection.remove('Jerry');
assert.strictEqual(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 9512416

Please sign in to comment.