diff --git a/server/scripts/import-tests/index.js b/server/scripts/import-tests/index.js index 2f1def28d..a968f67ca 100644 --- a/server/scripts/import-tests/index.js +++ b/server/scripts/import-tests/index.js @@ -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 = { /** @@ -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 // .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 /tests//data/references.csv + // doesn't exist in /build/tests//data/references.csv const referencesCsvPath = path.join(dataPath, 'references.csv'); let referencesCsv; @@ -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') @@ -157,8 +183,8 @@ const ariaAtImport = { } } await this.upsertTestPlanVersion( - exampleDir, - exampleNames[exampleDir], + testPlanDir, + exampleNames[testPlanDir], ariaAtRepo, commitHash, commitMessage, @@ -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(