Skip to content

Commit

Permalink
WIP: Migrate to fast-xml-parser
Browse files Browse the repository at this point in the history
The `xml2js-parser` package hasn't been updated in 6 years, so it's time
to move to a more up-to-date alternative. `fast-xml-parser` looks fairly
decent, has TypeScript declarations built-in and will allow us to debug
and iterate faster on changes in the future.

Closes #10
  • Loading branch information
mgrabovsky committed Mar 1, 2023
1 parent 9654877 commit ab758f1
Show file tree
Hide file tree
Showing 6 changed files with 254 additions and 189 deletions.
58 changes: 37 additions & 21 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"axios": "^1.3.4",
"buffer": "^6.0.3",
"classnames": "^2.3.1",
"fast-xml-parser": "^4.0.13",
"graphql": "^16.6.0",
"immutability-helper": "^3.1.1",
"linkify-react": "^4.1.0",
Expand All @@ -42,8 +43,7 @@
"typescript": "^4.9.5",
"uuid": "^9.0.0",
"validator": "^13.9.0",
"web-vitals": "^3.1.1",
"xml2js-parser": "^1.1.1"
"web-vitals": "^3.1.1"
},
"scripts": {
"start": "react-scripts start",
Expand Down
45 changes: 25 additions & 20 deletions src/components/TestSuites.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -104,45 +104,50 @@ const TestSuitesInternal: React.FC<TestSuitesInternalProps> = (props) => {
};

const mkLogLink = (log: TestCaseLogsEntry): JSX.Element => (
<ExternalLink href={log.$.href} key={log.$.name}>
{log.$.name}
<ExternalLink href={log.$href} key={log.$name}>
{log.$name}
</ExternalLink>
);

interface LogsLinksProps {
logs: TestCaseLogs[];
logs?: TestCaseLogsEntry | TestCaseLogsEntry[];
}

const LogsLinks: React.FC<LogsLinksProps> = ({ logs }) => {
if (!logs || _.isEmpty(logs[0].log)) return null;
if (!logs || _.isEmpty(logs)) return null;
if (!_.isArray(logs)) logs = [logs];
const logsLinks = mkSeparatedList(mkLogsLinks(logs));
return <p>Log files: {logsLinks}</p>;
};

const mkLogsLinks = (logs: TestCaseLogs[]): JSX.Element[] => {
/** logs[0].log - [log1, log2, log3] */
if (!logs[0] || _.isEmpty(logs[0].log)) return [];
return _.map(logs[0].log, (log) => mkLogLink(log));
const mkLogsLinks = (logs: TestCaseLogsEntry[] | undefined): JSX.Element[] => {
if (!logs || _.isEmpty(logs)) return [];
return _.map(logs, (log) => mkLogLink(log));
};

const mkPhase = (phase: TestCasePhasesEntry): IRow => {
const logs = _.isArray(phase.logs?.log)
? phase.logs?.log
: phase.logs?.log
? [phase.logs?.log]
: [];
return {
cells: [
<TestStatusIcon status={phase.$.result} />,
phase.$.name,
mkSeparatedList(mkLogsLinks(phase.logs)),
<TestStatusIcon status={phase.$result} />,
phase.$name,
mkSeparatedList(mkLogsLinks(logs)),
],
key: phase.$.name,
key: phase.$name,
};
};

interface PhasesProps {
phases?: TestCasePhases[];
phases?: TestCasePhasesEntry[];
}

const Phases: React.FC<PhasesProps> = ({ phases }) => {
if (!phases || _.isEmpty(phases[0]?.phase)) return null;
const rows: IRow[] = _.map(phases[0].phase, (phase) => mkPhase(phase));
if (_.isEmpty(phases)) return null;
const rows: IRow[] = _.map(phases, (phase) => mkPhase(phase));
return (
<Table
aria-label="Table of individual phases within this test"
Expand All @@ -164,9 +169,9 @@ const Phases: React.FC<PhasesProps> = ({ phases }) => {

const mkTestOutput = (output: TestCaseTestOutputsEntry): IRow => ({
cells: [
<>{output.$.result}</>,
<>{output.$.message}</>,
<>{output.$.remedy}</>,
<>{output.$result}</>,
<>{output.$message}</>,
<>{output.$remedy}</>,
],
});

Expand Down Expand Up @@ -208,7 +213,7 @@ const TestCaseContent: React.FC<TestCaseContentProps> = (props) => {
return (
<>
<OutputsTable outputs={test['test-outputs']} />
<Phases phases={test.phases} />
<Phases phases={test.phases?.phase} />
</>
);
};
Expand Down Expand Up @@ -285,7 +290,7 @@ const TestCaseItem: React.FC<TestCaseItemProps> = (props) => {
</FlexItem>
)}
</Flex>
<LogsLinks logs={test.logs} />
<LogsLinks logs={test.logs?.log} />
</Flex>
</DataListCell>
);
Expand Down
Loading

0 comments on commit ab758f1

Please sign in to comment.