From 97e475b58a645202de2d04418db2ed156b9804f3 Mon Sep 17 00:00:00 2001 From: Howard Edwards Date: Thu, 29 Aug 2024 09:59:53 -0400 Subject: [PATCH 1/2] Account for resources folder being moved on w3c/aria-at --- server/scripts/import-tests/gitOperations.js | 2 +- server/scripts/import-tests/settings.js | 8 +++++++- .../scripts/import-tests/testPlanVersionOperations.js | 11 ++++------- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/server/scripts/import-tests/gitOperations.js b/server/scripts/import-tests/gitOperations.js index dcf947903..11312cf42 100644 --- a/server/scripts/import-tests/gitOperations.js +++ b/server/scripts/import-tests/gitOperations.js @@ -3,7 +3,7 @@ const spawn = require('cross-spawn'); const ariaAtRepo = 'https://github.com/w3c/aria-at.git'; -const ariaAtDefaultBranch = 'master'; +const ariaAtDefaultBranch = 'move-resources'; // TODO: Revert to 'master' before merging /** * Executes a git command and returns its output. diff --git a/server/scripts/import-tests/settings.js b/server/scripts/import-tests/settings.js index 4658a7310..489526680 100644 --- a/server/scripts/import-tests/settings.js +++ b/server/scripts/import-tests/settings.js @@ -3,5 +3,11 @@ const path = require('path'); const gitCloneDirectory = path.resolve(__dirname, 'tmp'); const builtTestsDirectory = path.resolve(gitCloneDirectory, 'build', 'tests'); const testsDirectory = path.resolve(gitCloneDirectory, 'tests'); +const resourcesDirectory = path.resolve(gitCloneDirectory, 'resources'); -module.exports = { gitCloneDirectory, builtTestsDirectory, testsDirectory }; +module.exports = { + gitCloneDirectory, + builtTestsDirectory, + testsDirectory, + resourcesDirectory +}; diff --git a/server/scripts/import-tests/testPlanVersionOperations.js b/server/scripts/import-tests/testPlanVersionOperations.js index 430d25109..ebcfe9657 100644 --- a/server/scripts/import-tests/testPlanVersionOperations.js +++ b/server/scripts/import-tests/testPlanVersionOperations.js @@ -21,7 +21,8 @@ const { parseTests } = require('./testParser'); const { gitCloneDirectory, builtTestsDirectory, - testsDirectory + testsDirectory, + resourcesDirectory } = require('./settings'); const { getAppUrl } = require('./utils'); @@ -66,8 +67,6 @@ const buildTestsAndCreateTestPlanVersions = async (commit, { transaction }) => { await updateAtsJson({ ats, supportAts: support.ats }); for (const directory of fse.readdirSync(builtTestsDirectory)) { - if (directory === 'resources') continue; - const builtDirectoryPath = path.join(builtTestsDirectory, directory); const sourceDirectoryPath = path.join(testsDirectory, directory); @@ -235,7 +234,7 @@ const processTestPlanVersion = async ({ * Imports the harness files from the test directory to the client resources. */ const importHarness = () => { - const sourceFolder = path.resolve(`${testsDirectory}/resources`); + const sourceFolder = path.resolve(`${resourcesDirectory}`); const targetFolder = path.resolve('../', 'client/resources'); console.info(`Updating harness directory, ${targetFolder} ...`); fse.rmSync(targetFolder, { recursive: true, force: true }); @@ -330,9 +329,7 @@ const flattenObject = (obj, parentKey = '') => { */ const updateJsons = async () => { // Commands path info for v1 format - const keysMjsPath = pathToFileURL( - path.join(testsDirectory, 'resources', 'keys.mjs') - ); + const keysMjsPath = pathToFileURL(path.join(resourcesDirectory, 'keys.mjs')); const commands = Object.entries(await import(keysMjsPath)).map( ([id, text]) => ({ id, text }) ); From 0a545608a308a644447ff9b96c0fa7b9871c4455 Mon Sep 17 00:00:00 2001 From: Howard Edwards Date: Tue, 3 Sep 2024 12:04:44 -0400 Subject: [PATCH 2/2] Support dynamic /resources and /tests/resources folder --- server/scripts/import-tests/settings.js | 22 +++++++++- .../import-tests/testPlanVersionOperations.js | 43 +++++++++++-------- 2 files changed, 44 insertions(+), 21 deletions(-) diff --git a/server/scripts/import-tests/settings.js b/server/scripts/import-tests/settings.js index 489526680..1f76524a2 100644 --- a/server/scripts/import-tests/settings.js +++ b/server/scripts/import-tests/settings.js @@ -1,13 +1,31 @@ const path = require('path'); +// https://github.com/w3c/aria-at/commit/9d73d6bb274b3fe75b9a8825e020c0546a33a162 +// This is the date of the last commit before the /build folder removal in +// 8f83b9808efc3f830481ef4d37599c299c8c4676. +// Meant to support backward compatability for older tests. +const buildRemovalDate = new Date('2022-03-10 18:08:36.000000 +00:00'); + +// https://github.com/w3c/aria-at/commit/40e5aece2ffda9598d91df490f10ef5abdbea0d9 TODO: // this may need to be updated if another commit is merged before this is ready +// This is the date of the last commit before the /resources folder was moved in +// TODO: . +// Used to account for /tests/resources instead of /resources. +const resourcesMovedDate = new Date('2024-08-29 09:35:44.000000 +00:00'); + const gitCloneDirectory = path.resolve(__dirname, 'tmp'); const builtTestsDirectory = path.resolve(gitCloneDirectory, 'build', 'tests'); const testsDirectory = path.resolve(gitCloneDirectory, 'tests'); -const resourcesDirectory = path.resolve(gitCloneDirectory, 'resources'); +const getResourcesDirectory = useResourcesInTestsFolder => + useResourcesInTestsFolder + ? path.resolve(gitCloneDirectory, 'tests', 'resources') + : path.resolve(gitCloneDirectory, 'resources'); module.exports = { + buildRemovalDate, + resourcesMovedDate, + gitCloneDirectory, builtTestsDirectory, testsDirectory, - resourcesDirectory + getResourcesDirectory }; diff --git a/server/scripts/import-tests/testPlanVersionOperations.js b/server/scripts/import-tests/testPlanVersionOperations.js index ebcfe9657..ab854f58a 100644 --- a/server/scripts/import-tests/testPlanVersionOperations.js +++ b/server/scripts/import-tests/testPlanVersionOperations.js @@ -19,10 +19,12 @@ const { dates } = require('shared'); const { readCommit, readDirectoryGitInfo } = require('./gitOperations'); const { parseTests } = require('./testParser'); const { + buildRemovalDate, + resourcesMovedDate, gitCloneDirectory, builtTestsDirectory, testsDirectory, - resourcesDirectory + getResourcesDirectory } = require('./settings'); const { getAppUrl } = require('./utils'); @@ -36,6 +38,7 @@ const { getAppUrl } = require('./utils'); const buildTestsAndCreateTestPlanVersions = async (commit, { transaction }) => { const { gitCommitDate } = await readCommit(gitCloneDirectory, commit); + console.log(`Using commit \`${commit ?? 'latest'}\`...\n`); console.log('Running `npm install` ...\n'); const installOutput = spawn.sync('npm', ['install'], { cwd: gitCloneDirectory @@ -59,25 +62,23 @@ const buildTestsAndCreateTestPlanVersions = async (commit, { transaction }) => { console.log('`npm run build` output', buildOutput.stdout.toString()); - importHarness(); + const useBuildInAppUrlPath = + gitCommitDate.getTime() <= buildRemovalDate.getTime(); + const useResourcesInTestsFolder = + gitCommitDate.getTime() <= resourcesMovedDate.getTime(); - const { support } = await updateJsons(); + importHarness(useResourcesInTestsFolder); + const { support } = await updateJsons(useResourcesInTestsFolder); const ats = await At.findAll(); await updateAtsJson({ ats, supportAts: support.ats }); for (const directory of fse.readdirSync(builtTestsDirectory)) { + if (directory === 'resources') continue; + const builtDirectoryPath = path.join(builtTestsDirectory, directory); const sourceDirectoryPath = path.join(testsDirectory, directory); - // https://github.com/w3c/aria-at/commit/9d73d6bb274b3fe75b9a8825e020c0546a33a162 - // This is the date of the last commit before the build folder removal. - // Meant to support backward compatability until the existing tests can - // be updated to the current structure - const buildRemovalDate = new Date('2022-03-10 18:08:36.000000 +00:00'); - const useBuildInAppAppUrlPath = - gitCommitDate.getTime() <= buildRemovalDate.getTime(); - if ( !( fse.existsSync(sourceDirectoryPath) && @@ -92,7 +93,7 @@ const buildTestsAndCreateTestPlanVersions = async (commit, { transaction }) => { builtDirectoryPath, sourceDirectoryPath, gitCommitDate, - useBuildInAppAppUrlPath, + useBuildInAppUrlPath, ats, transaction }); @@ -113,7 +114,7 @@ const buildTestsAndCreateTestPlanVersions = async (commit, { transaction }) => { * @param {string} options.directory - The directory name. * @param {string} options.builtDirectoryPath - Path to the built directory. * @param {string} options.sourceDirectoryPath - Path to the source directory. - * @param {boolean} options.useBuildInAppAppUrlPath - Whether to use build path in app URL. + * @param {boolean} options.useBuildInAppUrlPath - Whether to use build path in app URL. * @param {Array} options.ats - Array of AT objects. * @param {import('sequelize').Transaction} options.transaction - The database transaction. * @returns {Promise} @@ -122,7 +123,7 @@ const processTestPlanVersion = async ({ directory, builtDirectoryPath, sourceDirectoryPath, - useBuildInAppAppUrlPath, + useBuildInAppUrlPath, ats, transaction }) => { @@ -209,7 +210,7 @@ const processTestPlanVersion = async ({ directory, testPageUrl: getAppUrl(testPageUrl, { gitSha, - directoryPath: useBuildInAppAppUrlPath + directoryPath: useBuildInAppUrlPath ? builtDirectoryPath : sourceDirectoryPath }), @@ -232,9 +233,10 @@ const processTestPlanVersion = async ({ /** * Imports the harness files from the test directory to the client resources. + * @param {boolean} useResourcesInTestsFolder - whether to use /tests/resources vs /resources */ -const importHarness = () => { - const sourceFolder = path.resolve(`${resourcesDirectory}`); +const importHarness = useResourcesInTestsFolder => { + const sourceFolder = getResourcesDirectory(useResourcesInTestsFolder); const targetFolder = path.resolve('../', 'client/resources'); console.info(`Updating harness directory, ${targetFolder} ...`); fse.rmSync(targetFolder, { recursive: true, force: true }); @@ -325,11 +327,14 @@ const flattenObject = (obj, parentKey = '') => { /** * Updates JSON files for commands and support. + * @param {boolean} useResourcesInTestsFolder - whether to use /tests/resources vs /resources * @returns {Promise} An object containing the parsed support data. */ -const updateJsons = async () => { +const updateJsons = async useResourcesInTestsFolder => { // Commands path info for v1 format - const keysMjsPath = pathToFileURL(path.join(resourcesDirectory, 'keys.mjs')); + const keysMjsPath = pathToFileURL( + path.join(getResourcesDirectory(useResourcesInTestsFolder), 'keys.mjs') + ); const commands = Object.entries(await import(keysMjsPath)).map( ([id, text]) => ({ id, text }) );