Skip to content

Commit

Permalink
Make yarn tasks imply yarn install where appropriate (#11394)
Browse files Browse the repository at this point in the history
* made sure that yarn install gets called before compile

* Add some nice messages

* better detection

* cleaned up more

* more tweaks

* remove old checks

* let unit tests run without binaries

* turn off scenario tests until binaries can be installed

* add another rule
  • Loading branch information
fearthecowboy authored Sep 6, 2023
1 parent efa5c22 commit b4a70df
Show file tree
Hide file tree
Showing 10 changed files with 156 additions and 49 deletions.
13 changes: 8 additions & 5 deletions .github/workflows/ci_linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,14 @@ jobs:
run: yarn test
working-directory: Extension

- name: Run simple vscode unit tests
uses: GabrielBB/[email protected]
with:
run: yarn test --scenario=SingleRootProject
working-directory: Extension
# # NOTE : We can't run the test that require the native binary files
# # yet -- there will be an update soon that allows the tester to
# # acquire them on-the-fly
# - name: Run simple vscode unit tests
# uses: GabrielBB/[email protected]
# with:
# run: yarn test --scenario=SingleRootProject
# working-directory: Extension

# - name: Run languageServer integration tests
# uses: GabrielBB/[email protected]
Expand Down
13 changes: 8 additions & 5 deletions .github/workflows/ci_mac.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,14 @@ jobs:
run: yarn test
working-directory: Extension

- name: Run simple vscode unit tests
uses: GabrielBB/[email protected]
with:
run: yarn test --scenario=SingleRootProject
working-directory: Extension
# # NOTE : We can't run the test that require the native binary files
# # yet -- there will be an update soon that allows the tester to
# # acquire them on-the-fly
# - name: Run simple vscode unit tests
# uses: GabrielBB/[email protected]
# with:
# run: yarn test --scenario=SingleRootProject
# working-directory: Extension

# - name: Run languageServer integration tests
# uses: GabrielBB/[email protected]
Expand Down
9 changes: 6 additions & 3 deletions .github/workflows/ci_windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,12 @@ jobs:
run: yarn test
working-directory: Extension

- name: Run simple vscode unit tests
run: yarn test --scenario=SingleRootProject
working-directory: Extension
# # NOTE : We can't run the test that require the native binary files
# # yet -- there will be an update soon that allows the tester to
# # acquire them on-the-fly
# - name: Run simple vscode unit tests
# run: yarn test --scenario=SingleRootProject
# working-directory: Extension

# - name: Run languageServer integration tests
# run: yarn run integrationTests
Expand Down
1 change: 1 addition & 0 deletions Extension/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ module.exports = {
"no-unsafe-finally": "error",
"no-unused-expressions": "error",
"no-unused-labels": "error",
"space-before-blocks": "error",
"no-var": "error",
"one-var": [
"error",
Expand Down
4 changes: 2 additions & 2 deletions Extension/.scripts/code.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import { spawnSync } from 'child_process';
import { verbose } from '../src/Utility/Text/streams';
import { $args, $root, $scenario, brightGreen, checkFile, gray, green, pwd } from './common';
import { $args, $root, $scenario, assertAnyFile, brightGreen, gray, green, pwd } from './common';

import { resolve } from 'path';
import { getTestInfo } from '../test/common/selectTests';
Expand All @@ -25,7 +25,7 @@ export async function main() {
// we found it
$args.unshift(ti.workspace);
}
await checkFile('dist/src/main.js', `The extension entry point '${$root}/dist/src/main.js is missing. You should run ${brightGreen("yarn compile")}\n\n`);
await assertAnyFile('dist/src/main.js', `The extension entry point '${$root}/dist/src/main.js is missing. You should run ${brightGreen("yarn compile")}\n\n`);

const { cli, args } = await install();

Expand Down
85 changes: 69 additions & 16 deletions Extension/.scripts/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ export let $cmd = 'main';
export let $scenario = '';

// loop through the args and pick out --scenario=... and remove it from the $args and set $scenario
export const $args = process.argv.slice(2).filter(each => !(each.startsWith('--scenario=') && ($scenario = each.substring('--scenario='.length))));
process.argv.slice(2).filter(each => !(each.startsWith('--scenario=') && ($scenario = each.substring('--scenario='.length))));
export const $args = process.argv.slice(2).filter(each => !each.startsWith('--'));
export const $switches = process.argv.slice(2).filter(each => each.startsWith('--'));

/** enqueue the call to the callback function to happen on the next available tick, and return a promise to the result */
export function then<T>(callback: () => Promise<T> | T): Promise<T> {
Expand Down Expand Up @@ -166,10 +168,12 @@ export async function writeJson(filename: string, object: CommentJSONValue) {

export function error(text: string) {
console.error(`\n${red('ERROR')}: ${text}`);
return true;
}

export function warn(text: string) {
console.error(`\n${yellow('WARNING')}: ${text}`);
return true;
}

export function note(text: string) {
Expand Down Expand Up @@ -254,37 +258,86 @@ export function position(text: string) {
return gray(`${text}`);
}

export async function checkFolder(folder: string | string[], errMsg: string){
for (const each of is.array(folder) ? folder : [folder]) {
export async function assertAnyFolder(oneOrMoreFolders: string | string[], errorMessage?: string): Promise<string> {
oneOrMoreFolders = is.array(oneOrMoreFolders) ? oneOrMoreFolders : [oneOrMoreFolders];
for (const each of oneOrMoreFolders) {
const result = await filepath.isFolder(each, $root);
if (result) {
verbose(`Folder ${brightGreen(each)} exists.`);
return result;
}
}
error(errMsg);
process.exit(1);
if (errorMessage) {
if (!$switches.includes('--quiet')) {
error(errorMessage);
}
process.exit(1);
}
}

export async function checkFile(file: string | string[], errMsg: string){
for (const each of is.array(file) ? file : [file]) {
export async function assertAnyFile(oneOrMoreFiles: string | string[], errorMessage?: string): Promise<string> {
oneOrMoreFiles = is.array(oneOrMoreFiles) ? oneOrMoreFiles : [oneOrMoreFiles];
for (const each of oneOrMoreFiles) {
const result = await filepath.isFile(each, $root);
if (result) {
verbose(`Folder ${brightGreen(each)} exists.`);
return result;
}
}
error(errMsg);
process.exit(1);
if (errorMessage) {
if (!$switches.includes('--quiet')) {
error(errorMessage);
}
process.exit(1);
}
}

const quiet = process.argv.includes('--quiet');

export async function checkPrep() {
await checkFolder('dist/walkthrough', `The walkthrough files are not in place. You should run ${brightGreen("yarn prep")}\n\n`);
await checkFolder('dist/html', `The html files are not in place. You should run ${brightGreen("yarn prep")}\n\n`);
await checkFolder('dist/schema', `The html files are not in place. You should run ${brightGreen("yarn prep")}\n\n`);
await checkFile('dist/nls.metadata.json', `The extension translation file '${$root}/dist/nls.metadata.json is missing. You should run ${brightGreen("yarn prep")}\n\n`);
verbose('Prep files appear to be in place.');
let failing = false;

failing = !await assertAnyFolder('dist/test') && (quiet || warn(`The compiled test files are not in place.`)) || failing;
failing = !await assertAnyFolder('dist/walkthrough') && (quiet || warn(`The walkthrough files are not in place.`)) || failing;
failing = !await assertAnyFolder('dist/html') && (quiet || warn(`The html files are not in place.`)) || failing;
failing = !await assertAnyFolder('dist/schema') && (quiet || warn(`The schema files are not in place.`)) || failing;
failing = !await assertAnyFile('dist/nls.metadata.json') && (quiet || warn(`The extension translation file '${$root}/dist/nls.metadata.json is missing.`)) || failing;
failing = await checkDTS() || failing;

if (!failing) {
verbose('Prep files appear to be in place.');
}
return failing;
}

export async function checkCompiled() {
await checkFile('dist/src/main.js', `The extension entry point '${$root}/dist/src/main.js is missing. You should run ${brightGreen("yarn compile")}\n\n`);
verbose('Compiled files appear to be in place.');
let failing = false;
failing = await checkDTS() || failing;
failing = !await assertAnyFile('dist/src/main.js') && (quiet || warn(`The extension entry point '${$root}/dist/src/main.js is missing.`)) || failing;

if (!failing) {
verbose('Compiled files appear to be in place.');
}
return failing;
}

export async function checkDTS() {
let failing = false;
failing = !await assertAnyFile('vscode.d.ts') && (quiet || warn(`The VSCode import file '${$root}/dist/src/vscode.d.ts is missing.`)) || failing;
failing = !await assertAnyFile('vscode.proposed.terminalDataWriteEvent.d.ts') && (quiet || warn(`The VSCode import file '${$root}/dist/src/vscode.proposed.terminalDataWriteEvent.d.ts is missing.`)) || failing;

if (!failing) {
verbose('VSCode d.ts files appear to be in place.');
}
return failing;
}

export async function checkBinaries() {
let failing = false;
failing = !await assertAnyFile(['bin/cpptools.exe', 'bin/cpptools']) && (quiet || warn(`The native binary files are not present. You should either build or install the native binaries\n\n.`)) || failing;

if (!failing) {
verbose('Native binary files appear to be in place.');
}
return failing;
}
14 changes: 10 additions & 4 deletions Extension/.scripts/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { filepath } from '../src/Utility/Filesystem/filepath';
import { is } from '../src/Utility/System/guards';
import { verbose } from '../src/Utility/Text/streams';
import { getTestInfo } from '../test/common/selectTests';
import { $args, $root, $scenario, brightGreen, checkFile, checkFolder, cmdSwitch, cyan, error, gray, green, readJson, red, writeJson } from './common';
import { $args, $root, $scenario, assertAnyFile, assertAnyFolder, brightGreen, checkBinaries, cmdSwitch, cyan, error, gray, green, readJson, red, writeJson } from './common';
import { install, isolated, options } from './vscode';

export { install, reset } from './vscode';
Expand Down Expand Up @@ -73,14 +73,17 @@ function filterStdio() {
filterStdio();

async function unitTests() {
await checkFolder('dist/test/unit', `The folder '${$root}/dist/test/unit is missing. You should run ${brightGreen("yarn compile")}\n\n`);
const mocha = await checkFile(["node_modules/.bin/mocha.cmd", "node_modules/.bin/mocha"], `Can't find the mocha testrunner. You might need to run ${brightGreen("yarn install")}\n\n`);
await assertAnyFolder('dist/test/unit', `The folder '${$root}/dist/test/unit is missing. You should run ${brightGreen("yarn compile")}\n\n`);
const mocha = await assertAnyFile(["node_modules/.bin/mocha.cmd", "node_modules/.bin/mocha"], `Can't find the mocha testrunner. You might need to run ${brightGreen("yarn install")}\n\n`);
const result = spawnSync(mocha, [`${$root}/dist/test/unit/**/*.test.js`, '--timeout', '30000'], { stdio:'inherit'});
verbose(`\n${green("NOTE:")} If you want to run a scenario test (end-to-end) use ${cmdSwitch('scenario=<NAME>')} \n\n`);
return result.status;
}

async function scenarioTests(assets: string, name: string, workspace: string) {
if (await checkBinaries()) {
process.exit(1);
}
return runTests({
...options,
extensionDevelopmentPath: $root,
Expand All @@ -93,7 +96,7 @@ async function scenarioTests(assets: string, name: string, workspace: string) {
}

export async function main() {
await checkFolder('dist/test/', `The folder '${$root}/dist/test is missing. You should run ${brightGreen("yarn compile")}\n\n`);
await assertAnyFolder('dist/test/', `The folder '${$root}/dist/test is missing. You should run ${brightGreen("yarn compile")}\n\n`);
const arg = $args.find(each => !each.startsWith("--"));
const specifiedScenario = $scenario || env.SCENARIO || await getScenarioFolder(arg);
const testInfo = await getTestInfo(specifiedScenario);
Expand All @@ -114,6 +117,9 @@ export async function main() {
}

export async function all() {
if (await checkBinaries()) {
process.exit(1);
}
const finished: string[] = [];

if (await unitTests() !== 0) {
Expand Down
45 changes: 41 additions & 4 deletions Extension/.scripts/verify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,50 @@
* See 'LICENSE' in the project root for license information.
* ------------------------------------------------------------------------------------------ */

import { checkCompiled, checkPrep } from './common';
import { checkBinaries, checkCompiled, checkDTS, checkPrep, error, green } from './common';
const quiet = process.argv.includes('--quiet');

export async function main() {
await checkPrep();
await checkCompiled();
let failing = await checkPrep() && (quiet || error(`Files are not up to date. Run ${green('yarn prep')} to fix it.`));
failing = (await checkCompiled() && (quiet || error(`Compiled files are not present. Run ${green('yarn compile')} to fix it.`))) || failing;
failing = (await checkBinaries() && (quiet || error(`The native binary files are not present. You should either build or install the native binaries\n\n.`))) || failing;
if (failing) {
process.exit(1);
}
}

export async function compiled() {
let failing = false;
failing = (await checkCompiled() && (quiet || error(`Compiled files are not present. Run ${green('yarn compile')} to fix it.`))) || failing;

if (failing) {
process.exit(1);
}
}

export async function binaries() {
let failing = false;
failing = (await checkBinaries() && (quiet || error(`The native binary files are not present. You should either build or install the native binaries\n\n.`))) || failing;

if (failing) {
process.exit(1);
}
}

export async function prep() {
await checkPrep();
let failing = false;
failing = (await checkPrep() && (quiet || error(`Files are not up to date. Run ${green('yarn prep')} to fix it.`))) || failing;

if (failing) {
process.exit(1);
}
}

export async function dts() {
let failing = false;
failing = (await checkDTS() && (quiet || error(`VSCode import files are not present. Run ${green('yarn prep')} to fix it.`))) || failing;

if (failing) {
process.exit(1);
}
}
19 changes: 10 additions & 9 deletions Extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6121,24 +6121,25 @@
"scripts": "ts-node -T .scripts/scripts.ts",
"show": "ts-node -T .scripts/clean.ts show",
"clean": "ts-node -T .scripts/clean.ts",
"test": "ts-node -T .scripts/test.ts",
"code": "ts-node -T .scripts/code.ts",
"test": "yarn install && (yarn verify prep --quiet || yarn prep) && (yarn verify compiled --quiet || yarn build) && ts-node -T .scripts/test.ts",
"code": "yarn install && (yarn verify compiled --quiet || yarn build) && yarn verify binaries && ts-node -T .scripts/code.ts",
"verify": "ts-node -T .scripts/verify.ts",
"prep": "yarn copy-walkthrough-media && yarn generate-native-strings && yarn translations-generate",
"lint": "eslint -c .eslintrc.js --report-unused-disable-directives src test ui .scripts",
"compile": "(yarn verify prep || yarn prep) && tsc --build tsconfig.json",
"watch": "(yarn verify prep || yarn prep )&& tsc --build tsconfig.json --watch",
"rebuild": "yarn clean && yarn prep && yarn compile",
"prep": "yarn prep:dts && yarn copy-walkthrough-media && yarn generate-native-strings && yarn translations-generate",
"lint": "yarn install && eslint -c .eslintrc.js --report-unused-disable-directives src test ui .scripts",
"compile": "yarn install && (yarn verify prep --quiet || yarn prep) && yarn build",
"watch": "yarn install && (yarn verify prep --quiet || yarn prep) && tsc --build tsconfig.json --watch",
"rebuild": "yarn install && yarn clean && yarn prep && yarn build",
"vscode:prepublish": "yarn clean && yarn webpack",
"webpack": "yarn prep && tsc --build ui.tsconfig.json && webpack --mode production --env vscode_nls",
"webpack": "yarn install && (yarn verify prep --quiet || yarn prep) && tsc --build ui.tsconfig.json && webpack --mode production --env vscode_nls",
"generate-native-strings": "ts-node -T ./.scripts/generateNativeStrings.ts",
"generate-options-schema": "ts-node -T ./.scripts/generateOptionsSchema.ts",
"copy-walkthrough-media": "ts-node -T ./.scripts/copyWalkthruMedia.ts",
"translations-export": "yarn generate-native-strings && gulp translations-export",
"translations-generate": "set NODE_OPTIONS=--no-experimental-fetch && gulp translations-generate",
"translations-import": "gulp translations-import",
"import-edge-strings": "ts-node -T ./.scripts/import_edge_strings.ts",
"postinstall": "npx vscode-dts dev && npx vscode-dts main && yarn prep"
"prep:dts": "yarn verify dts --quiet || (npx vscode-dts dev && npx vscode-dts main)",
"build": "yarn prep:dts && echo [Building TypeScript code] && tsc --build tsconfig.json"
},
"devDependencies": {
"@octokit/rest": "^18.12.0",
Expand Down
2 changes: 1 addition & 1 deletion Extension/test/unit/commandLineParsing.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function marker() {
try {
throw new Error('Test Marker');
} catch (E) {
if (is.error(E)){
if (is.error(E)) {
return E.stack?.split('\n').filter(each => each.includes('.ts') && each.includes('<anonymous>')).join('\n');
}
}
Expand Down

0 comments on commit b4a70df

Please sign in to comment.