Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce duplication in process-test-directory builders #1107

Merged
merged 45 commits into from
Aug 29, 2024
Merged
Changes from 1 commit
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
65a98f0
wip: create process-test-directory folder and utils.js
howard-e Jul 16, 2024
6031e06
Add jest
howard-e Aug 5, 2024
4b5958a
Add mock content
howard-e Aug 5, 2024
ccd63ed
Update how create-all-tests.js is handled
howard-e Aug 5, 2024
68c4e66
Prepare process-test-directory scripts to be testable
howard-e Aug 6, 2024
2e31336
sample test run
howard-e Aug 6, 2024
fad789c
Add sample snapshot
howard-e Aug 6, 2024
e992888
Update tests
howard-e Aug 6, 2024
c6f2f84
Update snapshot
howard-e Aug 6, 2024
cd5cd85
Update snapshot
howard-e Aug 6, 2024
3c31e91
Support snapshots for the review pages
howard-e Aug 15, 2024
a1a7889
Simplify generate-and-commit-files.yml
howard-e Aug 15, 2024
383332d
Add test.yml workflow
howard-e Aug 15, 2024
6e6e5b4
Use dynamic import for test-reviewer
howard-e Aug 15, 2024
abdb938
Merge branch 'master' into add-tests
howard-e Aug 15, 2024
de399f9
Merge branch 'master' into reduce-duplication-test-builders
howard-e Aug 15, 2024
d42ddb1
Merge branch 'add-tests' into reduce-duplication-test-builders
howard-e Aug 15, 2024
51943b9
Use Utils class instead
howard-e Aug 19, 2024
c7e6183
Move additional utils
howard-e Aug 19, 2024
b562ce5
Move error handlers
howard-e Aug 19, 2024
a5ba199
Update JSDoc
howard-e Aug 19, 2024
4637bab
Fix error count for v1 generation script
howard-e Aug 19, 2024
fc2bfdf
Start moving functions from creaetReviewPages
howard-e Aug 20, 2024
392961b
Simplify patterns' page generation
howard-e Aug 20, 2024
960edb7
Move generating functions
howard-e Aug 20, 2024
0c7afc9
Flatten for loop when processing review pages
howard-e Aug 20, 2024
8689fcc
Extract referencesData collection function
howard-e Aug 20, 2024
6acad5a
Extract references and scripts data collecting functions
howard-e Aug 20, 2024
5ba3c27
Extract collectedTestsData to separate function
howard-e Aug 20, 2024
e6796cb
Extracted collectedTests functionality
howard-e Aug 20, 2024
b333622
Include console colors where applicable
howard-e Aug 20, 2024
b88d8ae
Merge branch 'add-tests' into reduce-duplication-test-builders
howard-e Aug 21, 2024
87e3962
Merge branch 'master' into reduce-duplication-test-builders
howard-e Aug 22, 2024
f22790f
Update to match latest master
howard-e Aug 22, 2024
19269f9
Additional rearranging
howard-e Aug 22, 2024
0495699
Additional updates
howard-e Aug 22, 2024
7bc6929
Standardize getScripts function and update snapshot
howard-e Aug 22, 2024
20ee398
Update tests
howard-e Aug 22, 2024
9e8bb4d
Move testHtml function
howard-e Aug 22, 2024
082ffab
Update log message
howard-e Aug 22, 2024
3c19c25
Update snapshots
howard-e Aug 23, 2024
091f126
Additional updates
howard-e Aug 23, 2024
10694c0
Reordering
howard-e Aug 23, 2024
edb7fdf
Merge branch 'master' into reduce-duplication-test-builders
howard-e Aug 26, 2024
fa942a8
Merge branch 'master' into reduce-duplication-test-builders
howard-e Aug 27, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Prepare process-test-directory scripts to be testable
howard-e committed Aug 6, 2024
commit 68c4e666565c6c8164ca7cd385aa7cbf76ecce76
25 changes: 16 additions & 9 deletions lib/data/process-test-directory-v1.js
Original file line number Diff line number Diff line change
@@ -30,11 +30,13 @@ const { createExampleScriptsTemplate } = require('./example-scripts-template');

/**
* @param {string} directory - path to directory of data to be used to generate test
* @param {string} buildOutputDirectory - path to build directory. Defaults to '<root>/build'
* @param {object} args={}
*/
const processTestDirectory = async ({ directory, args = {} }) => {
const processTestDirectory = async ({ directory, buildOutputDirectory, args = {} }) => {
let VERBOSE_CHECK = false;
let VALIDATE_CHECK = false;
let TEST_MODE = false;

let suppressedMessages = 0;

@@ -68,9 +70,10 @@ const processTestDirectory = async ({ directory, args = {} }) => {
process.exit(1);
};

// setup from arguments passed to npm script
// setup from arguments passed to npm script or test runner
VERBOSE_CHECK = !!args.verbose;
VALIDATE_CHECK = !!args.validate;
TEST_MODE = !!args.testMode;

const validModes = ['reading', 'interaction', 'item'];

@@ -91,8 +94,9 @@ const processTestDirectory = async ({ directory, args = {} }) => {
const referencesCsvFilePath = path.join(testPlanDirectory, 'data', 'referencesV1.csv');

// build output folders and file paths setup
const buildDirectory = path.join(rootDirectory, 'build');
const testPlanBuildDirectory = path.join(buildDirectory, 'tests', testPlanName);
const buildDirectory = buildOutputDirectory ?? path.join(rootDirectory, 'build');
const buildTestsDirectory = path.join(buildDirectory, 'tests');
const testPlanBuildDirectory = path.join(buildTestsDirectory, testPlanName);
const indexFileBuildOutputPath = path.join(testPlanBuildDirectory, 'index.html');

let backupTestsCsvFile, backupReferencesCsvFile;
@@ -807,7 +811,7 @@ ${rows}
const buildFiles = [
...createScriptFiles(scripts, testPlanBuildDirectory),
...exampleScriptedFiles.map(({ path: pathSuffix, content }) => ({
path: path.join('build', 'tests', testPlanName, pathSuffix),
path: path.join(buildTestsDirectory, testPlanName, pathSuffix),
content,
})),
...testsCollected.map(collectedTest =>
@@ -858,13 +862,16 @@ ${rows}
emitFile,
});

const prefixBuildPath = TEST_MODE ? '__test__/' : '';
const prefixTestsPath = TEST_MODE ? '__test__/__mocks__/' : '';

const existingRoot = new FileRecordChain({});
existingRoot.add('build', await existingBuildPromise);
existingRoot.add(`tests/${testPlanName}`, testPlanRecord);
existingRoot.add(`${prefixBuildPath}build`, await existingBuildPromise);
existingRoot.add(`${prefixTestsPath}tests/${testPlanName}`, testPlanRecord);

const newRoot = new FileRecordChain({});
newRoot.add('build', newBuild);
newRoot.add(`tests/${testPlanName}`, testPlanUpdate);
newRoot.add(`${prefixBuildPath}build`, newBuild);
newRoot.add(`${prefixTestsPath}tests/${testPlanName}`, testPlanUpdate);

const buildChanges = newRoot.changesAfter(existingRoot);

22 changes: 14 additions & 8 deletions lib/data/process-test-directory.js
Original file line number Diff line number Diff line change
@@ -32,9 +32,10 @@ const { createExampleScriptsTemplate } = require('./example-scripts-template');

/**
* @param {string} directory - path to directory of data to be used to generate test
* @param {string} buildOutputDirectory - path to build directory. Defaults to '<root>/build'
* @param {object} args={}
*/
const processTestDirectory = async ({ directory, args = {} }) => {
const processTestDirectory = async ({ directory, buildOutputDirectory, args = {} }) => {
let suppressedMessages = 0;

/**
@@ -70,6 +71,7 @@ const processTestDirectory = async ({ directory, args = {} }) => {
// setup from arguments passed to npm script
const VERBOSE_CHECK = !!args.verbose;
const VALIDATE_CHECK = !!args.validate;
const TEST_MODE = !!args.testMode;

/** Name of the test plan. */
const testPlanName = path.basename(directory);
@@ -90,8 +92,9 @@ const processTestDirectory = async ({ directory, args = {} }) => {
const scriptsCsvFilePath = path.join(testPlanDirectory, 'data', 'scripts.csv');

// build output folders and file paths setup
const buildDirectory = path.join(rootDirectory, 'build');
const testPlanBuildDirectory = path.join(buildDirectory, 'tests', testPlanName);
const buildDirectory = buildOutputDirectory ?? path.join(rootDirectory, 'build');
const buildTestsDirectory = path.join(buildDirectory, 'tests');
const testPlanBuildDirectory = path.join(buildTestsDirectory, testPlanName);
const indexFileBuildOutputPath = path.join(testPlanBuildDirectory, 'index.html');

const existingBuildPromise = FileRecordChain.read(buildDirectory, {
@@ -1015,7 +1018,7 @@ ${rows}
const buildFiles = [
...createScriptFiles(scriptsSource, testPlanBuildDirectory),
...exampleScriptedFiles.map(({ path: pathSuffix, content }) => ({
path: path.join('build', 'tests', testPlanName, pathSuffix),
path: path.join(buildTestsDirectory, testPlanName, pathSuffix),
content,
})),
// TODO: If there is a need to individually view jaws-pcCursor or nvda-browseMode for example
@@ -1084,13 +1087,16 @@ ${rows}
emitFile,
});

const prefixBuildPath = TEST_MODE ? '__test__/' : '';
const prefixTestsPath = TEST_MODE ? '__test__/__mocks__/' : '';

const existingRoot = new FileRecordChain({});
existingRoot.add('build', await existingBuildPromise);
existingRoot.add(`tests/${testPlanName}`, testPlanRecord);
existingRoot.add(`${prefixBuildPath}build`, await existingBuildPromise);
existingRoot.add(`${prefixTestsPath}tests/${testPlanName}`, testPlanRecord);

const newRoot = new FileRecordChain({});
newRoot.add('build', newBuild);
newRoot.add(`tests/${testPlanName}`, testPlanUpdate);
newRoot.add(`${prefixBuildPath}build`, newBuild);
newRoot.add(`${prefixTestsPath}tests/${testPlanName}`, testPlanUpdate);

const buildChanges = newRoot.changesAfter(existingRoot);

26 changes: 19 additions & 7 deletions scripts/create-all-tests/createAllTests.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
const path = require('path');

const fse = require('fs-extra');

const {
processTestDirectory: processTestDirectoryV2,
} = require('../../lib/data/process-test-directory');
const {
processTestDirectory: processTestDirectoryV1,
} = require('../../lib/data/process-test-directory-v1');

const args = require('minimist')(process.argv.slice(2), {
const cliArgs = require('minimist')(process.argv.slice(2), {
alias: {
h: 'help',
t: 'testplan',
@@ -20,7 +18,7 @@ const args = require('minimist')(process.argv.slice(2), {
},
});

if (args.help) {
if (cliArgs.help) {
console.log(`Default use:
No arguments:
Generate tests and view report summary.
@@ -41,7 +39,21 @@ if (args.help) {
process.exit();
}

/**
*
* @param {object} config
* @param {object} config.args
* @param {string} config.args.testplan
* @param {boolean} config.args.validate
* @param {boolean} config.args.verbose
* @param {boolean} config.args.testMode
* @param {string} config.buildOutputDirectory
* @param {string} config.testsDirectory
* @returns {Promise<void>}
*/
async function createAllTests({ config } = {}) {
const args = config?.args ?? cliArgs;

// on some OSes, it seems the `npm_config_testplan` environment variable will come back as the actual variable name rather than empty if it does not exist
const TARGET_TEST_PLAN =
args.testplan && !args.testplan.includes('npm_config_testplan') ? args.testplan : null; // individual test plan to generate test assets for
@@ -53,9 +65,7 @@ async function createAllTests({ config } = {}) {

const scriptsDirectory = path.dirname(__filename);
const rootDirectory = path.join(scriptsDirectory, '../..');
const testsDirectory = config?.testsDirectory
? config.testsDirectory
: path.join(rootDirectory, 'tests');
const testsDirectory = config?.testsDirectory ?? path.join(rootDirectory, 'tests');

const filteredTestPlans = fse.readdirSync(testsDirectory).filter(f =>
TARGET_TEST_PLAN
@@ -88,6 +98,7 @@ async function createAllTests({ config } = {}) {
if (FALLBACK_V2_CHECK || V2_CHECK) {
return processTestDirectoryV2({
directory: path.join('tests', directory),
buildOutputDirectory: config?.buildOutputDirectory,
args,
}).catch(error => {
error.directory = directory;
@@ -96,6 +107,7 @@ async function createAllTests({ config } = {}) {
} else if (FALLBACK_V1_CHECK || V1_CHECK) {
return processTestDirectoryV1({
directory: path.join('tests', directory),
buildOutputDirectory: config?.buildOutputDirectory,
args,
}).catch(error => {
error.directory = directory;