Skip to content

Commit

Permalink
Define middle ground between not generated and not tested
Browse files Browse the repository at this point in the history
  • Loading branch information
Soremwar committed Feb 4, 2021
1 parent a99ce93 commit 3c3a490
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 31 deletions.
34 changes: 28 additions & 6 deletions node/testdata/common.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { join } from "../../path/mod.ts";

/**
* The test suite matches the folders inside the `test` folder inside the
* node repo
Expand All @@ -9,15 +11,35 @@ type TestSuites = Record<string, string[]>;

interface Config {
nodeVersion: string;
/** Ignored files won't be run, deleted or updated by the update script */
/** Ignored files won't regenerated by the update script */
ignore: TestSuites;
/**
* The files that will be run by the test suite
*
* The files to be generated with the update script must be listed here as well,
* but they won't be regenerated if they are listed in the `ignore` configuration
* */
tests: TestSuites;
suitesFolder: string;
versionsFolder: string;
}

export async function getConfig(): Promise<Config> {
return JSON.parse(
await Deno.readTextFile(new URL("./config.json", import.meta.url)),
);
}
export const config: Config = JSON.parse(
await Deno.readTextFile(new URL("./config.json", import.meta.url)),
);

export const ignoreList = Object.entries(config.ignore).reduce(
(total: RegExp[], [suite, paths]) => {
paths.forEach((path) => total.push(new RegExp(join(suite, path))));
return total;
},
[],
);

export const testList = Object.entries(config.tests).reduce(
(total: RegExp[], [suite, paths]) => {
paths.forEach((path) => total.push(new RegExp(join(suite, path))));
return total;
},
[],
);
16 changes: 3 additions & 13 deletions node/testdata/runner.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { walk } from "../../fs/walk.ts";
import { dirname, fromFileUrl, join } from "../../path/mod.ts";
import { getConfig } from "./common.ts";
import { dirname, fromFileUrl } from "../../path/mod.ts";
import { config, testList } from "./common.ts";

/**
* This script will run the test files specified in the configuration file
Expand All @@ -11,19 +11,9 @@ import { getConfig } from "./common.ts";
* Usage: `deno run --allow-run --allow-read runner.ts`
*/

const config = await getConfig();

const match = Object.entries(config.tests).reduce(
(total: RegExp[], [suite, paths]) => {
paths.forEach((path) => total.push(new RegExp(join(suite, path))));
return total;
},
[],
);

const dir = walk(fromFileUrl(new URL(config.suitesFolder, import.meta.url)), {
includeDirs: false,
match,
match: testList,
});

for await (const file of dir) {
Expand Down
27 changes: 15 additions & 12 deletions node/testdata/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Untar } from "../../archive/tar.ts";
import { walk } from "../../fs/walk.ts";
import { basename, fromFileUrl, join, resolve } from "../../path/mod.ts";
import { ensureFile } from "../../fs/ensure_file.ts";
import { getConfig } from "./common.ts";
import { config, ignoreList } from "./common.ts";

/**
* This script will download and extract the test files specified in the
Expand All @@ -18,8 +18,6 @@ import { getConfig } from "./common.ts";
const NODE_URL = "https://nodejs.org/dist/vNODE_VERSION";
const NODE_FILE = "node-vNODE_VERSION.tar.gz";

const config = await getConfig();

/** URL for the download */
const url = `${NODE_URL}/${NODE_FILE}`.replaceAll(
"NODE_VERSION",
Expand Down Expand Up @@ -70,19 +68,11 @@ async function downloadFile(url: string, path: string) {
async function clearTests() {
console.log("Cleaning up previous tests");

const ignore = Object.entries(config.ignore).reduce(
(total: RegExp[], [suite, paths]) => {
paths.forEach((path) => total.push(new RegExp(join(suite, path))));
return total;
},
[],
);

const files = walk(
(fromFileUrl(new URL(config.suitesFolder, import.meta.url))),
{
includeDirs: false,
skip: ignore,
skip: ignoreList,
},
);

Expand All @@ -91,7 +81,20 @@ async function clearTests() {
}
}

/**
* This will iterate over the ignore and test lists defined in the
* configuration file
*
* If it were to be found in the ignore list or not found in the test list, the
* function will return undefined, meaning the file won't be regenerated
*/
function getRequestedFileSuite(file: string): string | undefined {
for(const regex of ignoreList){
if(regex.test(file)){
return;
}
}

for (const suite in config.tests) {
for (const regex of config.tests[suite]) {
if (new RegExp(regex).test(file)) {
Expand Down

0 comments on commit 3c3a490

Please sign in to comment.