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

Support resources/ folder being moved on w3c/aria-at for tests import #1207

Draft
wants to merge 2 commits into
base: development
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion server/scripts/import-tests/gitOperations.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Placing another reminder to change this before merging

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or actually I realize now that this is using the aria-at branch that should make this build over here. Perhaps the issues with CI point to a larger issue with the paths?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also wondering that too. Will investigate

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be fixed now in 0a54560


/**
* Executes a git command and returns its output.
Expand Down
26 changes: 25 additions & 1 deletion server/scripts/import-tests/settings.js
Original file line number Diff line number Diff line change
@@ -1,7 +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: <insert the commit when aria-at#1096 is merged>.
// Used to account for <ROOT>/tests/resources instead of <ROOT>/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 getResourcesDirectory = useResourcesInTestsFolder =>
useResourcesInTestsFolder
? path.resolve(gitCloneDirectory, 'tests', 'resources')
: path.resolve(gitCloneDirectory, 'resources');

module.exports = {
buildRemovalDate,
resourcesMovedDate,

module.exports = { gitCloneDirectory, builtTestsDirectory, testsDirectory };
gitCloneDirectory,
builtTestsDirectory,
testsDirectory,
getResourcesDirectory
};
40 changes: 21 additions & 19 deletions server/scripts/import-tests/testPlanVersionOperations.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,12 @@ const { dates } = require('shared');
const { readCommit, readDirectoryGitInfo } = require('./gitOperations');
const { parseTests } = require('./testParser');
const {
buildRemovalDate,
resourcesMovedDate,
gitCloneDirectory,
builtTestsDirectory,
testsDirectory
testsDirectory,
getResourcesDirectory
} = require('./settings');
const { getAppUrl } = require('./utils');

Expand All @@ -35,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
Expand All @@ -58,9 +62,13 @@ 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 });
Expand All @@ -71,14 +79,6 @@ const buildTestsAndCreateTestPlanVersions = async (commit, { transaction }) => {
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) &&
Expand All @@ -93,7 +93,7 @@ const buildTestsAndCreateTestPlanVersions = async (commit, { transaction }) => {
builtDirectoryPath,
sourceDirectoryPath,
gitCommitDate,
useBuildInAppAppUrlPath,
useBuildInAppUrlPath,
ats,
transaction
});
Expand All @@ -114,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<void>}
Expand All @@ -123,7 +123,7 @@ const processTestPlanVersion = async ({
directory,
builtDirectoryPath,
sourceDirectoryPath,
useBuildInAppAppUrlPath,
useBuildInAppUrlPath,
ats,
transaction
}) => {
Expand Down Expand Up @@ -210,7 +210,7 @@ const processTestPlanVersion = async ({
directory,
testPageUrl: getAppUrl(testPageUrl, {
gitSha,
directoryPath: useBuildInAppAppUrlPath
directoryPath: useBuildInAppUrlPath
? builtDirectoryPath
: sourceDirectoryPath
}),
Expand All @@ -233,9 +233,10 @@ const processTestPlanVersion = async ({

/**
* Imports the harness files from the test directory to the client resources.
* @param {boolean} useResourcesInTestsFolder - whether to use <ROOT>/tests/resources vs <ROOT>/resources
*/
const importHarness = () => {
const sourceFolder = path.resolve(`${testsDirectory}/resources`);
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 });
Expand Down Expand Up @@ -326,12 +327,13 @@ const flattenObject = (obj, parentKey = '') => {

/**
* Updates JSON files for commands and support.
* @param {boolean} useResourcesInTestsFolder - whether to use <ROOT>/tests/resources vs <ROOT>/resources
* @returns {Promise<Object>} 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(testsDirectory, 'resources', 'keys.mjs')
path.join(getResourcesDirectory(useResourcesInTestsFolder), 'keys.mjs')
);
const commands = Object.entries(await import(keysMjsPath)).map(
([id, text]) => ({ id, text })
Expand Down
Loading