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
Extract collectedTestsData to separate function
  • Loading branch information
howard-e committed Aug 20, 2024
commit 5ba3c27732283a71ed5efe0d882b7443f89c26c5
52 changes: 5 additions & 47 deletions scripts/test-reviewer/createReviewPages.mjs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import path from 'path';
import fse from 'fs-extra';
import { spawnSync } from 'child_process';
import np from 'node-html-parser';
import getReferencesData from './getReferencesData.mjs';
import getReferenceForDirectory from './getReferenceForDirectory.mjs';
import getReferencesData from './getReferencesData.mjs';
import getScriptsData from './getScriptsData.mjs';
import getCollectedTestsData from './getCollectedTestsData.mjs';
import { generatePatternPages, generateIndexPage } from './generateReviewPages.mjs';
import { commandsAPI as CommandsAPI } from '../../tests/resources/at-commands.mjs';

@@ -109,51 +109,9 @@ export function createReviewPages(config) {
const scriptsData = getScriptsData(testPlanDirectory);
scripts.push(...scriptsData);

fse.readdirSync(testPlanBuildDirectory).forEach(function (test) {
if (
path.extname(test) === '.html' &&
!/\.collected\.html$/.test(test) &&
path.basename(test) !== 'index.html'
) {
const testFile = path.join(testsBuildDirectory, directory, test);
const root = np.parse(fse.readFileSync(testFile, 'utf8'), { script: true });

// Get testData from test-review-{presentationNumber}-{testId}-{modes}.json
const testData = JSON.parse(
fse.readFileSync(
path.join(testPlanBuildDirectory, path.parse(test).name + '.json'),
'utf8'
)
);

// Get metadata help links
const testFullName = root.querySelector('title').innerHTML;
const helpLinks = [];
for (let link of root.querySelectorAll('link')) {
if (link.attributes.rel === 'help') {
let href = link.attributes.href;
// V2
let text = link.attributes.title;

// V1
if (!text) {
if (href.indexOf('#') >= 0) {
text = `ARIA specification: ${href.split('#')[1]}`;
} else {
text = `APG example: ${href.split('examples/')[1]}`;
}
}

helpLinks.push({
link: href,
text: text,
});
}
}

collectedTests.push({ ...testData, test, testFullName, helpLinks });
}
});
// Process test plan build directory's `test-{xx}-{testId}.html` files
const collectedTestsData = getCollectedTestsData(testPlanBuildDirectory);
collectedTests.push(...collectedTestsData);

collectedTests.forEach(({ test, testFullName, helpLinks, ...testData }) => {
const testNumber = tests.length + 1;
59 changes: 59 additions & 0 deletions scripts/test-reviewer/getCollectedTestsData.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import path from 'path';
import fse from 'fs-extra';
import np from 'node-html-parser';

/**
* @param {string} testPlanBuildDirectory
* @returns {*[]}
*/
function getCollectedTestsData(testPlanBuildDirectory) {
const collectedTests = [];

fse.readdirSync(testPlanBuildDirectory).forEach(function (file) {
// Don't process unless the file is `test-{xx}-{testId}.html`
if (path.extname(file) !== '.html' || path.basename(file) === 'index.html') return;

// Ignore `test-{xx}-{testId}-{at}.collected.html`. More information to be collected from
// `test-{xx}-{testId}.html` file instead
if (/\.collected\.html$/.test(file)) return;

const testFile = path.join(testPlanBuildDirectory, file);
const root = np.parse(fse.readFileSync(testFile, 'utf8'), { script: true });

// Get testData from test-review-{presentationNumber}-{testId}-{modes}.json
const testJsonData = JSON.parse(
fse.readFileSync(path.join(testPlanBuildDirectory, path.parse(file).name + '.json'), 'utf8')
);

// Get metadata help links
const testFullName = root.querySelector('title').innerHTML;
const helpLinks = [];
for (let link of root.querySelectorAll('link')) {
if (link.attributes.rel === 'help') {
let href = link.attributes.href;
// V2
let text = link.attributes.title;

// V1
if (!text) {
if (href.indexOf('#') >= 0) {
text = `ARIA specification: ${href.split('#')[1]}`;
} else {
text = `APG example: ${href.split('examples/')[1]}`;
}
}

helpLinks.push({
link: href,
text: text,
});
}
}

collectedTests.push({ ...testJsonData, test: file, testFullName, helpLinks });
});

return collectedTests;
}

export default getCollectedTestsData;