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

Allow import-tests to account for both the old and new build structure when importing from aria-at #309

Closed
wants to merge 3 commits into from
Closed
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
65 changes: 46 additions & 19 deletions server/scripts/import-tests/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ const client = new Client();
const ariaAtRepo = 'https://github.com/w3c/aria-at.git';
const DEFAULT_BRANCH = 'master';
const tmpDirectory = path.resolve(__dirname, 'tmp');
const testDirectory = path.resolve(tmpDirectory, 'tests');
const supportFile = path.resolve(testDirectory, 'support.json');
const testsBuildDirectory = path.resolve(tmpDirectory, 'build', 'tests');
const testsDirectory = path.resolve(tmpDirectory, 'tests');

const ariaAtImport = {
/**
Expand Down Expand Up @@ -78,27 +78,56 @@ const ariaAtImport = {
commit = await nodegit.Commit.lookup(repo, latestCommit);
}

// use to conditionally determine paths to use based on whether or not
// the commit pulled for the aria-at repo is the old or new structure
const buildDirExists = fse.existsSync(testsBuildDirectory);
const supportFile = buildDirExists
? path.resolve(testsBuildDirectory, 'support.json')
: path.resolve(testsDirectory, 'support.json');

let commitDate = commit.date();
let commitMessage = commit.message();
let commitHash = commit.id().tostrS();

const support = JSON.parse(fse.readFileSync(supportFile));
const ats = support.ats;
for (let at of ats) await this.upsertAt(at.name); // TODO: will we need to port support for at.key as well?
for (let at of ats) await this.upsertAt(at.name);

const exampleNames = {};
for (let example of support.examples)
exampleNames[example.directory] = example.name;

let exampleDirs = fse.readdirSync(testDirectory);
for (let i = 0; i < exampleDirs.length; i++) {
const exampleDir = exampleDirs[i];
const subDirFullPath = path.join(testDirectory, exampleDir);
const stat = fse.statSync(subDirFullPath); // folder stats
let testPlanDirs = fse.readdirSync(
buildDirExists ? testsBuildDirectory : testsDirectory
);
for (let i = 0; i < testPlanDirs.length; i++) {
const testPlanDir = testPlanDirs[i];
const testPlanDirPath = path.join(
buildDirExists ? testsBuildDirectory : testsDirectory,
testPlanDir
);

// check source location of test plan directories because of the new 'build' directory set up
const sourceTestPlanDirPath = path.join(
testsDirectory,
testPlanDir
);
const stat = fse.statSync(testPlanDirPath); // folder stats

// <repo>.git/tests/resources folder shouldn't be factored in the tests
if (stat.isDirectory() && exampleDir !== 'resources') {
const dataPath = path.join(subDirFullPath, 'data');
if (
fse.existsSync(sourceTestPlanDirPath) && // explicitly check if source test plan directory exists
stat.isDirectory() &&
testPlanDir !== 'resources'
) {
// check multiple locations for relevant data folder that contains references.csv
const dataPath = path.join(
buildDirExists ? sourceTestPlanDirPath : testPlanDirPath,
'data'
);

// 'references.csv' only exists in <root>/tests/<directory>/data/references.csv
// doesn't exist in <root>/build/tests/<directory>/data/references.csv
const referencesCsvPath = path.join(dataPath, 'references.csv');

let referencesCsv;
Expand All @@ -124,22 +153,19 @@ const ariaAtImport = {
.filter(line => line.includes('designPattern'));

const tests = [];
const testFiles = fse.readdirSync(subDirFullPath);
const testFiles = fse.readdirSync(testPlanDirPath);

for (let j = 0; j < testFiles.length; j++) {
const testFile = testFiles[j];
const testFullPath = path.join(subDirFullPath, testFile);
const testPath = path.join(testPlanDirPath, testFile);
if (
path.extname(testFile) === '.html' &&
testFile !== 'index.html'
) {
// Get the testFile name from the html file
const htmlFile = path.relative(
tmpDirectory,
testFullPath
);
const htmlFile = path.relative(tmpDirectory, testPath);
const root = np.parse(
fse.readFileSync(testFullPath, 'utf8'),
fse.readFileSync(testPath, 'utf8'),
{ script: true }
);
const testFullName = root.querySelector('title')
Expand All @@ -157,8 +183,8 @@ const ariaAtImport = {
}
}
await this.upsertTestPlanVersion(
exampleDir,
exampleNames[exampleDir],
testPlanDir,
exampleNames[testPlanDir],
ariaAtRepo,
commitHash,
commitMessage,
Expand Down Expand Up @@ -201,6 +227,7 @@ const ariaAtImport = {
* @param {string} commitDate - the date of the latest versions of the tests pulled from the {@param ariaAtRepo} repository
* @param {string[]} exampleRefLine - the example url link pulled from the references.csv file related to the test
* @param {string[]} practiceGuidelinesRefLine - the APG (ARIA Practices Guidelines) link pulled from the references.csv file related to the test
* @param {object[]} tests - test steps for the test plan pulled from the {@param ariaAtRepo} repository
* @returns {number} - returns TestPlanVersion.id
*/
async upsertTestPlanVersion(
Expand Down