Skip to content

Commit

Permalink
feat: upgrade new test schema
Browse files Browse the repository at this point in the history
  • Loading branch information
kokororin committed Dec 10, 2023
1 parent b012f05 commit f662cad
Show file tree
Hide file tree
Showing 8 changed files with 901 additions and 804 deletions.
14 changes: 4 additions & 10 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,14 @@ module.exports = {
'plugin:prettier/recommended'
],
rules: {
'no-sync': 'error',
'prefer-promise-reject-errors': 'off',
'n/no-sync': 'error',
'n/prefer-promises/fs': 'error',
'prettier/prettier': [
'error',
{
endOfLine: 'auto'
}
],
'@typescript-eslint/no-floating-promises': [
'error',
{
ignoreVoid: true,
ignoreIIFE: false
}
],
'@typescript-eslint/prefer-nullish-coalescing': [
'error',
{ ignoreConditionalTests: true, ignoreMixedLogicalExpressions: true }
Expand All @@ -50,7 +42,9 @@ module.exports = {
allowAny: true
}
],
'@typescript-eslint/restrict-template-expressions': 'off'
'@typescript-eslint/restrict-template-expressions': 'off',
'@typescript-eslint/no-unsafe-argument': 'off',
'@typescript-eslint/unbound-method': 'off'
},
settings: {
'import/parsers': {
Expand Down
38 changes: 20 additions & 18 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
"watch": "tsc -watch -p ./",
"trash": "trash out",
"generate": "tsx scripts/generate.ts",
"postinstall": "node ./node_modules/phpfmt/v2/install && node ./node_modules/vscode/bin/install",
"postinstall": "node ./node_modules/phpfmt/v2/install",
"pretest": "npm run build",
"test": "cross-env CODE_TESTS_WORKSPACE=testProject node ./node_modules/vscode/bin/test",
"test": "cross-env CODE_TESTS_WORKSPACE=testProject node ./out/test/runTest.js",
"format": "prettier --write .",
"lint": "eslint --ext .ts,.js --fix src test scripts",
"prepublishOnly": "npm run build && vsce publish"
Expand Down Expand Up @@ -624,36 +624,38 @@
"@types/md5": "^2.3.2",
"@types/mocha": "^9.1.0",
"@types/node": "^17.0.13",
"@types/semver": "^7.3.13",
"@typescript-eslint/eslint-plugin": "^5.52.0",
"@typescript-eslint/parser": "^5.52.0",
"@types/semver": "^7.5.6",
"@types/vscode": "^1.60.0",
"@typescript-eslint/eslint-plugin": "^6.13.2",
"@typescript-eslint/parser": "^6.13.2",
"@vscode/test-electron": "^2.3.8",
"adm-zip": "^0.5.10",
"cross-env": "^7.0.3",
"eslint": "^8.34.0",
"eslint-config-prettier": "^8.6.0",
"eslint-config-standard-with-typescript": "^34.0.0",
"eslint-import-resolver-typescript": "^3.5.3",
"eslint-plugin-import": "^2.27.5",
"eslint-plugin-n": "^15.6.1",
"eslint-plugin-prettier": "^4.2.1",
"eslint": "^8.55.0",
"eslint-config-prettier": "^9.1.0",
"eslint-config-standard-with-typescript": "^42.0.0",
"eslint-import-resolver-typescript": "^3.6.1",
"eslint-plugin-import": "^2.29.0",
"eslint-plugin-n": "^16.3.1",
"eslint-plugin-prettier": "^5.0.1",
"eslint-plugin-promise": "^6.1.1",
"fast-glob": "^3.3.2",
"fs-extra": "^11.1.1",
"md5": "^2.3.0",
"mocha": "^9.2.0",
"prettier": "^2.8.8",
"prettier": "^3.1.0",
"simple-git": "^3.19.1",
"trash-cli": "^5.0.0",
"tsx": "^3.12.6",
"typescript": "^4.9.4",
"vscode": "^1.1.37"
"tsx": "^4.6.2",
"typescript": "^5.3.3"
},
"dependencies": {
"dayjs": "^1.11.7",
"dayjs": "^1.11.10",
"detect-indent": "^6.0.0",
"find-up": "^5.0.0",
"mem": "^8.1.1",
"phpfmt": "^0.0.6",
"pjson": "^1.0.9",
"semver": "^7.5.0"
"semver": "^7.5.4"
}
}
4 changes: 2 additions & 2 deletions src/PHPFmt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,8 @@ export class PHPFmt {
});
const origIniPath = iniPath;

const workspaceFolder = workspaceFolders.find(folder =>
iniPath?.startsWith(folder.uri.fsPath)
const workspaceFolder = workspaceFolders.find(
folder => iniPath?.startsWith(folder.uri.fsPath)
);
iniPath = workspaceFolder != null ? origIniPath : undefined;
}
Expand Down
24 changes: 0 additions & 24 deletions test/index.ts

This file was deleted.

26 changes: 26 additions & 0 deletions test/runTest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import path from 'path';
import assert from 'assert';
import { runTests } from '@vscode/test-electron';
import findUp from 'find-up';

async function run(): Promise<void> {
const pkgPath = await findUp('package.json', {
cwd: __dirname
});
assert.ok(pkgPath);
const extensionDevelopmentPath = path.dirname(pkgPath);
const extensionTestsPath = path.join(__dirname, 'suite');
const testWorkspace = path.join(extensionDevelopmentPath, 'testProject');

await runTests({
extensionDevelopmentPath,
extensionTestsPath,
launchArgs: [testWorkspace]
.concat(['--skip-welcome'])
.concat(['--disable-extensions'])
.concat(['--skip-release-notes'])
.concat(['--enable-proposed-api'])
});
}

void run();
18 changes: 8 additions & 10 deletions test/extension.test.ts → test/suite/extension.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,17 @@ import {
workspace as Workspace,
window as Window,
commands as Commands,
extensions as Extensions,
type Extension
extensions as Extensions
} from 'vscode';
import pjson from 'pjson';

const pkg = pjson as any;

suite('PHPFmt Test', () => {
const extension = Extensions.getExtension(
`${pkg.author}.${pkg.name}`
) as Extension<any>;

test('extension should be present', () => {
assert.ok(extension);
});
const extension = Extensions.getExtension(`${pkg.author}.${pkg.name}`);

test('can activate', async () => {
assert.ok(extension);
await extension.activate();
assert.ok(true);
});
Expand Down Expand Up @@ -54,7 +48,11 @@ suite('PHPFmt Test', () => {
});

test('should commands work', () => {
const commands = pkg.contributes.commands as any[];
const commands = pkg.contributes.commands as Array<{
command: string;
title: string;
when?: string;
}>;
commands
.filter(value => !value.when)
.forEach(command => {
Expand Down
29 changes: 29 additions & 0 deletions test/suite/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/* eslint-disable n/no-sync */
import * as path from 'path';
import Mocha from 'mocha';
import { sync as globSync } from 'fast-glob';

export function run(
testsRoot: string,
cb: (error: any, failures?: number) => void
): void {
// Create the mocha test
const mocha = new Mocha({
ui: 'tdd'
});

const files = globSync('**/**.test.js', { cwd: testsRoot });

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

try {
// Run the mocha test
mocha.run(failures => {
cb(null, failures);
});
} catch (err) {
console.error(err);
cb(err);
}
}
Loading

0 comments on commit f662cad

Please sign in to comment.