Skip to content

Commit

Permalink
chore: update benchmarks, coverage threshold; improve types and names
Browse files Browse the repository at this point in the history
  • Loading branch information
tatomyr committed Oct 22, 2024
1 parent 36161d7 commit 321e4d2
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 14 deletions.
2 changes: 1 addition & 1 deletion benchmark/chart.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const constructBarForChart = (x) => {
};

const output = [
'| CLI Version | Performance benchmark (test duration) |',
'| CLI Version | Performance benchmark (test duration diff) |',
'|---|---|',
...arr.map(
([cliVersion, mean]) =>
Expand Down
2 changes: 1 addition & 1 deletion benchmark/make-test-command.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ set -eo pipefail # Fail on script errors
git clone https://github.com/Rebilly/api-definitions.git

# Store the command into a text file:
echo hyperfine -i --warmup 3 $(cat package.json | jq '.dependencies' | jq 'keys' | jq 'map("'\''node node_modules/" + . + "/bin/cli.js lint api-definitions/openapi/openapi.yaml'\''")' | jq 'join(" ")' | xargs) --export-markdown benchmark_check.md --export-json benchmark_check.json > test-command.txt
echo hyperfine -i --warmup 3 $(cat package.json | jq '.dependencies' | jq 'keys' | jq 'map("'\''node node_modules/" + . + "/bin/cli.js lint public@core --config=api-definitions/redocly.yaml'\''")' | jq 'join(" ")' | xargs) --export-markdown benchmark_check.md --export-json benchmark_check.json > test-command.txt

# Put the command in the test section of the package.json:
cat package.json | jq ".scripts.test = \"$(cat test-command.txt)\"" > package.json
4 changes: 4 additions & 0 deletions benchmark/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@
"cli-1.19": "npm:@redocly/[email protected]",
"cli-1.20": "npm:@redocly/[email protected]",
"cli-1.21": "npm:@redocly/[email protected]",
"cli-1.22": "npm:@redocly/[email protected]",
"cli-1.23": "npm:@redocly/[email protected]",
"cli-1.24": "npm:@redocly/[email protected]",
"cli-1.25": "npm:@redocly/[email protected]",
"cli-next": "file:../redocly-cli.tgz"
}
}
12 changes: 6 additions & 6 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ module.exports = {
coverageThreshold: {
'packages/core/': {
statements: 80,
branches: 71,
functions: 74,
branches: 72,
functions: 75,
lines: 80,
},
'packages/cli/': {
statements: 60,
branches: 49,
functions: 60,
lines: 60,
statements: 63,
branches: 52,
functions: 63,
lines: 63,
},
},
testMatch: ['**/__tests__/**/*.test.ts', '**/*.test.ts'],
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/bundle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ function makeBundleVisitor(
},
},
Root: {
enter(root: any, ctx: any) {
enter(root: any, ctx: UserContext) {
rootLocation = ctx.location;
if (version === SpecMajorVersion.OAS3) {
components = root.components = root.components || {};
Expand All @@ -417,7 +417,7 @@ function makeBundleVisitor(

if (version === SpecMajorVersion.OAS3) {
visitor.DiscriminatorMapping = {
leave(mapping: Record<string, string>, ctx: any) {
leave(mapping: Record<string, string>, ctx: UserContext) {
for (const name of Object.keys(mapping)) {
const $ref = mapping[name];
const resolved = ctx.resolve({ $ref });
Expand Down
8 changes: 4 additions & 4 deletions packages/core/src/resolve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ export class BaseResolver {
return new Source(absoluteRef, body, mimeType);
} else {
if (fs.lstatSync(absoluteRef).isDirectory()) {
throw new Error(`Expected a file but received a folder at ${absoluteRef}`);
throw new Error(`Expected a file but received a folder at ${absoluteRef}.`);
}
const content = await fs.promises.readFile(absoluteRef, 'utf-8');
// In some cases file have \r\n line delimeters like on windows, we should skip it.
Expand Down Expand Up @@ -233,7 +233,7 @@ export async function resolveDocument(opts: {
}): Promise<ResolvedRefMap> {
const { rootDocument, externalRefResolver, rootType } = opts;
const resolvedRefMap: ResolvedRefMap = new Map();
const seedNodes = new Set<string>(); // format "${type}::${absoluteRef}${pointer}"
const seenNodes = new Set<string>(); // format "${type}::${absoluteRef}${pointer}"

const resolvePromises: Array<Promise<void>> = [];
resolveRefsInParallel(rootDocument.parsed, rootDocument, '#/', rootType);
Expand Down Expand Up @@ -262,11 +262,11 @@ export async function resolveDocument(opts: {
}

const nodeId = `${type.name}::${nodeAbsoluteRef}`;
if (seedNodes.has(nodeId)) {
if (seenNodes.has(nodeId)) {
return;
}

seedNodes.add(nodeId);
seenNodes.add(nodeId);

const [_, anchor] = Object.entries(node).find(([key]) => key === '$anchor') || [];
if (anchor) {
Expand Down

0 comments on commit 321e4d2

Please sign in to comment.