diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml index a0a0bbd1..64fd5453 100644 --- a/.github/workflows/unit-tests.yml +++ b/.github/workflows/unit-tests.yml @@ -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 \ No newline at end of file + - uses: actions/checkout@v1 + - run: npm ci + - run: npm ci --prefix cli + - run: npm run bundle + - run: npm test diff --git a/.gitignore b/.gitignore index d3e74c33..0ba02826 100644 --- a/.gitignore +++ b/.gitignore @@ -28,7 +28,7 @@ bundles/ typings/* !typings/styled-patch.d.ts cli/index.js -cli/__test__/*/**/redoc-static.html +cli/__test__/*/**/*.html /benchmark/revisions diff --git a/cli/__test__/build/configRedoc/index.test.ts b/cli/__test__/build/configRedoc/index.test.ts index f201d6a0..9dacb177 100644 --- a/cli/__test__/build/configRedoc/index.test.ts +++ b/cli/__test__/build/configRedoc/index.test.ts @@ -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'); }); }); diff --git a/cli/__test__/build/configRedoc/inlineOptions.test.ts b/cli/__test__/build/configRedoc/inlineOptions.test.ts new file mode 100644 index 00000000..46d4e7e9 --- /dev/null +++ b/cli/__test__/build/configRedoc/inlineOptions.test.ts @@ -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"}'); + } + }); +}); diff --git a/cli/index.ts b/cli/index.ts index 4550ddd8..bc40bf6d 100644 --- a/cli/index.ts +++ b/cli/index.ts @@ -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; diff --git a/package.json b/package.json index e7bc57be..1c9b1b2a 100644 --- a/package.json +++ b/package.json @@ -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",