Skip to content

Commit

Permalink
chore: add e2e tests for build-docs
Browse files Browse the repository at this point in the history
  • Loading branch information
IgorKarpiuk committed Jul 26, 2023
1 parent 3a6322c commit 08f0894
Show file tree
Hide file tree
Showing 9 changed files with 104 additions and 1 deletion.
23 changes: 23 additions & 0 deletions __tests__/build-docs/build-docs-with-config-option/index.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<!DOCTYPE html>
<html>

<head>
<meta charset="utf8" />
<title>{{title}}</title>
<!-- needed for adaptive design -->
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
body {
padding: 0;
margin: 0;
}
</style>
{{{redocHead}}}
{{#unless disableGoogleFont}}<link href="https://fonts.googleapis.com/css?family=Montserrat:300,400,700|Roboto:300,400,700" rel="stylesheet">{{/unless}}
</head>

<body>
{{{redocHTML}}}
</body>

</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
type: object
properties:
message:
type: string
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
openapi: 3.1.0
servers:
- url: http://localhost
info:
title: Sample API
version: 1.0.0
paths:
/hello:
get:
operationId: getMessage
security: []
summary: Get a greeting message
responses:
200:
description: OK
content:
application/json:
schema:
$ref: ./message-schema.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
extends:
- minimal
theme:
openapi:
htmlTemplate: ../index.hbs
10 changes: 10 additions & 0 deletions __tests__/build-docs/build-docs-with-config-option/snapshot.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`E2E build-docs build docs with config option 1`] = `
🎉 bundled successfully in: nested/redoc-static.html (38 KiB) [⏱ <test>ms].
Found nested/redocly.yaml and using theme.openapi options
Prerendering docs
`;
1 change: 1 addition & 0 deletions __tests__/build-docs/simple-build-docs/pets.yaml
10 changes: 10 additions & 0 deletions __tests__/build-docs/simple-build-docs/snapshot.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`E2E build-docs simple build-docs 1`] = `
🎉 bundled successfully in: redoc-static.html (318 KiB) [⏱ <test>ms].
Found undefined and using theme.openapi options
Prerendering docs
`;
30 changes: 30 additions & 0 deletions __tests__/commands.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { join, relative } from 'path';
//@ts-ignore
import { toMatchSpecificSnapshot } from './specific-snapshot';
import { getCommandOutput, getEntrypoints, callSerializer, getParams } from './helpers';
import * as fs from 'fs';

expect.extend({
toMatchExtendedSpecificSnapshot(received, snapshotFile) {
Expand Down Expand Up @@ -372,4 +373,33 @@ describe('E2E', () => {
(<any>expect(result)).toMatchSpecificSnapshot(join(testPath, 'snapshot.js'));
});
});

describe('build-docs', () => {
const folderPath = join(__dirname, 'build-docs');

test('simple build-docs', () => {
const testPath = join(folderPath, 'simple-build-docs');
const args = getParams('../../../packages/cli/src/index.ts', 'build-docs', [
'pets.yaml',
]);
const result = getCommandOutput(args, testPath);
(<any>expect(result)).toMatchSpecificSnapshot(join(testPath, 'snapshot.js'));

expect(fs.existsSync(join(testPath, 'redoc-static.html'))).toEqual(true);
});

test('build docs with config option', () => {
const testPath = join(folderPath, 'build-docs-with-config-option');
const args = getParams('../../../packages/cli/src/index.ts', 'build-docs', [
'nested/openapi.yaml',
'--config=nested/redocly.yaml',
'-o=nested/redoc-static.html',
]);
const result = getCommandOutput(args, testPath);
(<any>expect(result)).toMatchSpecificSnapshot(join(testPath, 'snapshot.js'));

expect(fs.existsSync(join(testPath, 'nested/redoc-static.html'))).toEqual(true);
expect(fs.statSync(join(testPath, 'nested/redoc-static.html')).size).toEqual(38839)
});
});
});
3 changes: 2 additions & 1 deletion __tests__/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ type CLICommands =
| 'preview-docs'
| 'push'
| 'split'
| 'stats';
| 'stats'
| 'build-docs';

export function getParams(
indexEntryPoint: string,
Expand Down

0 comments on commit 08f0894

Please sign in to comment.