Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
joedixon committed Oct 10, 2023
1 parent 3c2e9fa commit a528a7b
Show file tree
Hide file tree
Showing 15 changed files with 2,106 additions and 2,831 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ node_modules
.vscode-test/
.vsix
.DS_Store
out
4,631 changes: 1,880 additions & 2,751 deletions package-lock.json

Large diffs are not rendered by default.

41 changes: 25 additions & 16 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"version": "1.5.3",
"publisher": "calebporzio",
"engines": {
"vscode": "^1.17.0"
"vscode": "^1.74.0"
},
"repository": {
"type": "git",
Expand Down Expand Up @@ -77,13 +77,13 @@
"description": "A custom phpunit binary. Ex: 'phpunit', '/usr/local/bin/phpunit'"
},
"better-phpunit.pestBinary": {
"type": [
"string",
"null"
],
"default": null,
"description": "A custom Pest binary. Ex: 'pest', '/usr/local/bin/pest'"
},
"type": [
"string",
"null"
],
"default": null,
"description": "A custom Pest binary. Ex: 'pest', '/usr/local/bin/pest'"
},
"better-phpunit.xmlConfigFilepath": {
"type": [
"string",
Expand Down Expand Up @@ -211,16 +211,25 @@
]
},
"scripts": {
"postinstall": "node ./node_modules/vscode/bin/install",
"test": "node ./node_modules/vscode/bin/test"
"vscode:prepublish": "npm run compile",
"compile": "tsc -p ./",
"watch": "tsc -watch -p ./",
"pretest": "npm run compile",
"test": "node ./out/test/runTest.js"
},
"devDependencies": {
"@types/mocha": "^2.2.42",
"@types/node": "^7.10.2",
"eslint": "^4.6.1",
"mocha": "^4.1.0",
"typescript": "^2.5.2",
"vscode": "^1.1.22"
"@types/glob": "^7.1.1",
"@types/mocha": "^10.0.1",
"@types/node": "^20.8.4",
"@types/vscode": "^1.74.0",
"@typescript-eslint/eslint-plugin": "^6.7.0",
"@typescript-eslint/parser": "^6.7.0",
"@vscode/test-electron": "^2.3.0",
"eslint": "^8.26.0",
"glob": "^7.1.4",
"mocha": "^10.2.0",
"source-map-support": "^0.5.12",
"typescript": "^5.2.2"
},
"dependencies": {
"find-up": "^2.1.0"
Expand Down
24 changes: 24 additions & 0 deletions src/test/runTest.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/test/runTest.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 24 additions & 0 deletions src/test/runTest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import * as path from 'path';

import { runTests } from '@vscode/test-electron';

async function main() {
try {
// The folder containing the Extension Manifest package.json
// Passed to `--extensionDevelopmentPath`
const extensionDevelopmentPath = path.resolve(__dirname, '../../');

// The path to the extension test script
// Passed to --extensionTestsPath
const extensionTestsPath = path.resolve(__dirname, './suite/index');
const testWorkspace = path.resolve(__dirname, '../../test/project-stub');

// Download VS Code, unzip it and run the integration test
await runTests({ extensionDevelopmentPath, extensionTestsPath, launchArgs: [testWorkspace], });
} catch (err) {
console.error('Failed to run tests');
process.exit(1);
}
}

main();
45 changes: 23 additions & 22 deletions test/extension.test.js → src/test/suite/extension.test.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
const assert = require('assert');
import * as assert from 'assert';
import { beforeEach, afterEach } from 'mocha';
const vscode = require('vscode');
const path = require('path');
const extension = require('../src/extension');
import * as path from 'path';
const extension = require('../../../src/extension');
const waitToAssertInSeconds = 5;

// This is a little helper function to promisify setTimeout, so we can "await" setTimeout.
function timeout(seconds, callback) {
function timeout(seconds: any, callback: any) {
return new Promise(resolve => {
setTimeout(() => {
callback();
resolve();
resolve('');
}, seconds * waitToAssertInSeconds);
});
}

describe("Better PHPUnit Test Suite", function () {
suite("Better PHPUnit Test Suite", function () {
beforeEach(async () => {
// Reset the test/project-stub/.vscode/settings.json settings for each test.
// This allows us to test config options in tests and not harm other tests.
Expand All @@ -37,7 +38,7 @@ describe("Better PHPUnit Test Suite", function () {
await vscode.workspace.getConfiguration("better-phpunit").update("docker.enable", false);
});

it("Run file outside of method", async () => {
test("Run file outside of method", async () => {
let document = await vscode.workspace.openTextDocument(path.join(vscode.workspace.rootPath, 'tests', 'SampleTest.php'));
await vscode.window.showTextDocument(document);
await vscode.commands.executeCommand('better-phpunit.run');
Expand All @@ -47,7 +48,7 @@ describe("Better PHPUnit Test Suite", function () {
});
});

it("Run file", async () => {
test("Run file", async () => {
let document = await vscode.workspace.openTextDocument(path.join(vscode.workspace.rootPath, 'tests', 'SampleTest.php'));
await vscode.window.showTextDocument(document, { selection: new vscode.Range(7, 0, 7, 0) });
await vscode.commands.executeCommand('better-phpunit.run-file');
Expand All @@ -60,7 +61,7 @@ describe("Better PHPUnit Test Suite", function () {
});
});

it("Run from within first method", async () => {
test("Run from within first method", async () => {
let document = await vscode.workspace.openTextDocument(path.join(vscode.workspace.rootPath, 'tests', 'SampleTest.php'));
await vscode.window.showTextDocument(document, { selection: new vscode.Range(7, 0, 7, 0) });
await vscode.commands.executeCommand('better-phpunit.run');
Expand All @@ -73,7 +74,7 @@ describe("Better PHPUnit Test Suite", function () {
});
});

it("Run from within second method", async () => {
test("Run from within second method", async () => {
let document = await vscode.workspace.openTextDocument(path.join(vscode.workspace.rootPath, 'tests', 'SampleTest.php'));
await vscode.window.showTextDocument(document, { selection: new vscode.Range(12, 0, 12, 0) });
await vscode.commands.executeCommand('better-phpunit.run');
Expand All @@ -86,7 +87,7 @@ describe("Better PHPUnit Test Suite", function () {
});
});

it("Detect filename", async () => {
test("Detect filename", async () => {
let document = await vscode.workspace.openTextDocument(path.join(vscode.workspace.rootPath, 'tests', 'SampleTest.php'));
await vscode.window.showTextDocument(document);
await vscode.commands.executeCommand('better-phpunit.run');
Expand All @@ -99,7 +100,7 @@ describe("Better PHPUnit Test Suite", function () {
});
});

it("Detect filename with a space", async () => {
test("Detect filename with a space", async () => {
let document = await vscode.workspace.openTextDocument(path.join(vscode.workspace.rootPath, 'tests', 'File With Spaces Test.php'));
await vscode.window.showTextDocument(document);
await vscode.commands.executeCommand('better-phpunit.run');
Expand All @@ -112,7 +113,7 @@ describe("Better PHPUnit Test Suite", function () {
});
});

it("Detect executable", async () => {
test("Detect executable", async () => {
let document = await vscode.workspace.openTextDocument(path.join(vscode.workspace.rootPath, 'tests', 'SampleTest.php'));
await vscode.window.showTextDocument(document);
await vscode.commands.executeCommand('better-phpunit.run');
Expand All @@ -125,7 +126,7 @@ describe("Better PHPUnit Test Suite", function () {
});
});

it("Detect executable in sub-directory", async () => {
test("Detect executable in sub-directory", async () => {
let document = await vscode.workspace.openTextDocument(path.join(vscode.workspace.rootPath, 'sub-directory', 'tests', 'SampleTest.php'));
await vscode.window.showTextDocument(document);
await vscode.commands.executeCommand('better-phpunit.run');
Expand All @@ -138,7 +139,7 @@ describe("Better PHPUnit Test Suite", function () {
});
});

it("Detect configuration in sub-directory", async () => {
test("Detect configuration in sub-directory", async () => {
let document = await vscode.workspace.openTextDocument(path.join(vscode.workspace.rootPath, 'sub-directory', 'tests', 'SampleTest.php'));
await vscode.window.showTextDocument(document);
await vscode.commands.executeCommand('better-phpunit.run');
Expand All @@ -151,7 +152,7 @@ describe("Better PHPUnit Test Suite", function () {
});
});

it("Uses configuration found in path supplied in settings", async () => {
test("Uses configuration found in path supplied in settings", async () => {
await vscode.workspace.getConfiguration('better-phpunit').update('xmlConfigFilepath', '/var/log/phpunit.xml');
let document = await vscode.workspace.openTextDocument(path.join(vscode.workspace.rootPath, 'sub-directory', 'tests', 'SampleTest.php'));
await vscode.window.showTextDocument(document);
Expand All @@ -165,7 +166,7 @@ describe("Better PHPUnit Test Suite", function () {
});
});

it("Check full command", async () => {
test("Check full command", async () => {
let document = await vscode.workspace.openTextDocument(path.join(vscode.workspace.rootPath, 'tests', 'SampleTest.php'));
await vscode.window.showTextDocument(document, { selection: new vscode.Range(7, 0, 7, 0) });
await vscode.commands.executeCommand('better-phpunit.run');
Expand All @@ -178,7 +179,7 @@ describe("Better PHPUnit Test Suite", function () {
});
});

it("Run previous", async () => {
test("Run previous", async () => {
let document = await vscode.workspace.openTextDocument(path.join(vscode.workspace.rootPath, 'tests', 'OtherTest.php'));
await vscode.window.showTextDocument(document, { selection: new vscode.Range(12, 0, 12, 0) });
await vscode.commands.executeCommand('better-phpunit.run-previous');
Expand All @@ -191,7 +192,7 @@ describe("Better PHPUnit Test Suite", function () {
});
});

it("Run entire suite", async () => {
test("Run entire suite", async () => {
let document = await vscode.workspace.openTextDocument(path.join(vscode.workspace.rootPath, 'tests', 'SampleTest.php'));
await vscode.window.showTextDocument(document, { selection: new vscode.Range(7, 0, 7, 0) });
await vscode.commands.executeCommand('better-phpunit.run-suite')
Expand All @@ -204,7 +205,7 @@ describe("Better PHPUnit Test Suite", function () {
});
});

it("Run entire suite with specified options", async () => {
test("Run entire suite with specified options", async () => {
await vscode.workspace.getConfiguration('better-phpunit').update('suiteSuffix', '--testsuite unit --coverage');
let document = await vscode.workspace.openTextDocument(path.join(vscode.workspace.rootPath, 'tests', 'SampleTest.php'));
await vscode.window.showTextDocument(document, { selection: new vscode.Range(7, 0, 7, 0) });
Expand All @@ -218,7 +219,7 @@ describe("Better PHPUnit Test Suite", function () {
});
});

it("Run with commandSuffix config", async () => {
test("Run with commandSuffix config", async () => {
await vscode.workspace.getConfiguration('better-phpunit').update('commandSuffix', '--foo=bar');

let document = await vscode.workspace.openTextDocument(path.join(vscode.workspace.rootPath, 'tests', 'SampleTest.php'));
Expand All @@ -233,7 +234,7 @@ describe("Better PHPUnit Test Suite", function () {
});
});

it("Run with phpunitBinary config", async () => {
test("Run with phpunitBinary config", async () => {
await vscode.workspace.getConfiguration('better-phpunit').update('phpunitBinary', 'vendor/foo/bar');

let document = await vscode.workspace.openTextDocument(path.join(vscode.workspace.rootPath, 'tests', 'SampleTest.php'));
Expand Down
40 changes: 40 additions & 0 deletions src/test/suite/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/test/suite/index.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 37 additions & 0 deletions src/test/suite/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import * as path from 'path';
import * as Mocha from 'mocha';
import * as glob from 'glob';

export function run(): Promise<void> {
// Create the mocha test
const mocha = new Mocha({
ui: 'tdd'
});

const testsRoot = path.resolve(__dirname, '..');

return new Promise((c, e) => {
glob('**/**.test.js', { cwd: testsRoot }, (err, files) => {
if (err) {
return e(err);
}

// Add files to the test suite
files.forEach(f => mocha.addFile(path.resolve(testsRoot, f)));

try {
// Run the mocha test
mocha.run(failures => {
if (failures > 0) {
e(new Error(`${failures} tests failed.`));
} else {
c();
}
});
} catch (err) {
console.error(err);
e(err);
}
});
});
}
Loading

0 comments on commit a528a7b

Please sign in to comment.