test: .redocly.yaml config is applied

This commit is contained in:
anastasiia-developer 2022-05-06 16:05:01 +03:00
parent 9c5e7ab1bd
commit 74c9e81f8d
6 changed files with 54 additions and 27 deletions

View File

@ -6,7 +6,8 @@ jobs:
build-and-unit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- run: npm ci
- run: npm run bundle
- run: npm test
- uses: actions/checkout@v1
- run: npm ci
- run: npm ci --prefix cli
- run: npm run bundle
- run: npm test

2
.gitignore vendored
View File

@ -28,7 +28,7 @@ bundles/
typings/*
!typings/styled-patch.d.ts
cli/index.js
cli/__test__/*/**/redoc-static.html
cli/__test__/*/**/*.html
/benchmark/revisions

View File

@ -1,28 +1,11 @@
import { spawnSync } from 'child_process';
import { readFileSync } from 'fs';
describe('build', () => {
it('should use .redocly.yaml', () => {
const r = spawnSync('node', ['../../../index.js', 'build', ' ../../../../demo/openapi.yaml'], {
cwd: __dirname,
shell: true,
});
const out = r.stdout.toString('utf-8');
const err = r.stderr.toString('utf-8');
const result = `${out}\n${err}`;
expect(result).toContain('Found .redocly.yaml and use option from features.openapi');
expect(result).toContain('bundled successfully');
});
it('should use inline options and ignore .redocly.yaml', () => {
const r = spawnSync(
'node',
[
'../../../index.js',
'build',
' ../../../../demo/openapi.yaml',
'--options.disableSearch=true',
],
['../../../index.js', 'build', ' ../../../../demo/openapi.yaml', '--output=redocTest.html'],
{
cwd: __dirname,
shell: true,
@ -32,7 +15,16 @@ describe('build', () => {
const out = r.stdout.toString('utf-8');
const err = r.stderr.toString('utf-8');
const result = `${out}\n${err}`;
expect(result).not.toContain('Found .redocly.yaml and use option from features.openapi');
try {
const redocStaticFile = readFileSync(`${__dirname}/redocTest.html`, 'utf8');
expect(redocStaticFile).toContain('"options":{"disableSearch":true}');
expect(redocStaticFile).not.toContain('role="search"');
} catch (err) {
expect(err.toString()).toContain('{"options":{"disableSearch":"true"}');
}
expect(result).toContain('Found .redocly.yaml and use options from features.openapi');
expect(result).toContain('bundled successfully');
});
});

View File

@ -0,0 +1,34 @@
import { spawnSync } from 'child_process';
import { readFileSync } from 'fs';
describe('build with inline options', () => {
it('should use inline options and ignore .redocly.yaml', () => {
const r = spawnSync(
'node',
[
'../../../index.js',
'build',
' ../../../../demo/openapi.yaml',
'--options.disableSearch="false" ',
],
{
cwd: __dirname,
shell: true,
},
);
const out = r.stdout.toString('utf-8');
const err = r.stderr.toString('utf-8');
const result = `${out}\n${err}`;
expect(result).not.toContain('Found .redocly.yaml and use options from features.openapi');
expect(result).toContain('bundled successfully');
try {
const redocStaticFile = readFileSync(`${__dirname}/redoc-static.html`, 'utf8');
expect(redocStaticFile).toContain('"options":{"disableSearch":"false"}');
expect(redocStaticFile).toContain('role="search"');
} catch (err) {
expect(err.toString()).toContain('"options":{"disableSearch":"false"}');
}
});
});

View File

@ -455,7 +455,7 @@ function getObjectOrJSON(options) {
default:
const configFile = findConfig();
if (configFile) {
console.log(`Found ${configFile} and use option from features.openapi`);
console.log(`Found ${configFile} and use options from features.openapi`);
try {
const config = parseYaml(readFileSync(configFile, 'utf-8')) as Config;

View File

@ -51,7 +51,7 @@
"lint": "eslint --fix 'src/**/*.{js,ts,tsx}' --cache",
"benchmark": "node ./benchmark/benchmark.js",
"start:demo": "webpack serve --hot --config demo/webpack.config.ts --mode=development",
"compile:cli": "cd cli/ && npm ci && cd ../ && tsc custom.d.ts cli/index.ts --target es6 --module commonjs --types yargs",
"compile:cli": "tsc custom.d.ts cli/index.ts --target es6 --module commonjs --types yargs",
"build:demo": "webpack --mode=production --config demo/webpack.config.ts",
"deploy:demo": "aws s3 sync demo/dist s3://production-redoc-demo --acl=public-read",
"license-check": "license-checker --production --onlyAllow 'MIT;ISC;Apache-2.0;BSD;BSD-2-Clause;BSD-3-Clause;CC-BY-4.0;Python-2.0' --summary",