Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 20 additions & 11 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Unit/Integration Tests
name: Unit/Integration Tests & Coverage

on:
pull_request:
Expand All @@ -11,20 +11,29 @@ jobs:
build-and-unit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
- uses: actions/checkout@v3
- name: Cache dependencies
uses: actions/cache@v3
with:
node-version: "15.x"
- name: cache node modules
uses: actions/cache@v1
with:
path: ~/.npm # npm cache files are stored in `~/.npm` on Linux/macOS
path: ~/.npm
key: npm-${{ hashFiles('package-lock.json') }}
restore-keys: |
npm-${{ hashFiles('package-lock.json') }}
npm-
- run: npm i -g npm@7.0.2
- run: npm install
- run: npm test && npm run e2e
- name: Install modules
run: |
echo
echo Using Node $(node -v), NPM $(npm -v)
echo
npm ci
- name: Unit Tests & Coverage Report
uses: artiomtr/jest-coverage-report-action@v2.0-rc.4
env:
CI: true
with:
annotations: none
test-script: npx jest ./packages --silent --ci --json --testLocationInResults --outputFile=report.json --bail --coverage || exit 0
- name: E2E Tests
run: npm run e2e
env:
CI: true
32 changes: 32 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
module.exports = {
clearMocks: true,
restoreMocks: true,
preset: 'ts-jest',
collectCoverageFrom: [
'packages/*/src/**/*.ts',
'!packages/**/__tests__/**/*',
'!packages/core/src/benchmark/**/*',
'!packages/cli/src/index.ts',
'!packages/cli/src/assert-node-version.ts',
],
coverageThreshold: {
'packages/core/': {
statements: 77,
branches: 69,
functions: 65,
lines: 77,
},
'packages/cli/': {
statements: 30,
branches: 27,
functions: 29,
lines: 32,
},
},
testMatch: ['**/__tests__/**/*.test.ts', '**/*.test.ts'],
globals: {
'ts-jest': {
diagnostics: false,
},
},
};
24 changes: 2 additions & 22 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
"scripts": {
"test": "npm run typecheck && npm run unit",
"unit": "jest ./packages --coverage --coverageReporters lcov text-summary",
"coverage:cli": "jest --roots packages/cli/src --coverage",
"coverage:core": "jest --roots packages/core/src --coverage",
"typecheck": "tsc --noEmit --skipLibCheck",
"e2e": "jest --roots=./__tests__/",
"prettier": "npx prettier --write \"**/*.{ts,js}\"",
Expand Down Expand Up @@ -63,27 +65,5 @@
"typescript": "4.3.3",
"webpack": "^4.44.1",
"webpack-cli": "^3.3.12"
},
"jest": {
"clearMocks": true,
"restoreMocks": true,
"preset": "ts-jest",
"collectCoverageFrom": [
"packages/**/*.ts",
"!packages/**/__tests__/**/*",
"!packages/cli/src/index.ts",
"!packages/core/src/benchmark/**/*",
"!packages/core/lib/**/*",
"!packages/cli/lib/**/*"
],
"testMatch": [
"**/__tests__/**/*.test.ts",
"**/*.test.ts"
],
"globals": {
"ts-jest": {
"diagnostics": false
}
}
}
}
File renamed without changes.
4 changes: 2 additions & 2 deletions packages/cli/src/commands/split/__tests__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe('#split', () => {
const componentsFiles: ComponentsFiles = {};

it('should split the file and show the success message', async () => {
const filePath = "./packages/cli/src/commands/split/__tests__/fixtures/spec.json";
const filePath = "packages/cli/src/commands/split/__tests__/fixtures/spec.json";
jest.spyOn(process.stderr, 'write').mockImplementation(() => true);

await handleSplit (
Expand All @@ -44,7 +44,7 @@ describe('#split', () => {


it('should use the correct separator', async () => {
const filePath = "./packages/cli/src/commands/split/__tests__/fixtures/spec.json";
const filePath = "packages/cli/src/commands/split/__tests__/fixtures/spec.json";

const utils = require('../../../utils');
jest.spyOn(utils, 'pathToFilename').mockImplementation(() => 'newFilePath');
Expand Down
17 changes: 0 additions & 17 deletions packages/core/__tests__/lint.test.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import outdent from 'outdent';
import * as path from 'path';

import { bundleDocument, bundle } from '../src/bundle';

import { parseYamlToDocument, yamlSerializer } from './utils';
import { LintConfig, Config, ResolvedConfig } from '../src/config';
import { BaseResolver } from '../src/resolve';
import { bundleDocument, bundle } from '../bundle';
import { parseYamlToDocument, yamlSerializer } from '../../__tests__/utils';
import { LintConfig, Config, ResolvedConfig } from '../config';
import { BaseResolver } from '../resolve';

describe('bundle', () => {
expect.addSnapshotSerializer(yamlSerializer);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { outdent } from 'outdent';

import { getLineColLocation, getCodeframe } from '../src/format/codeframes';
import { LocationObject } from '../src/walk';
import { Source } from '../src/resolve';
import { getLineColLocation, getCodeframe } from '../format/codeframes';
import { LocationObject } from '../walk';
import { Source } from '../resolve';

describe('Location', () => {
it('should correctly calculate location for key', () => {
Expand Down
13 changes: 13 additions & 0 deletions packages/core/src/__tests__/lint.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { lintFromString, lintConfig, lintDocument } from '../lint';
import { BaseResolver } from '../resolve';
import { loadConfig } from '../config/load';
import { parseYamlToDocument, replaceSourceWithRef, makeConfig } from '../../__tests__/utils';
import { detectOpenAPI } from '../oas-types';

describe('lint', () => {
it('lintFromString should work', async () => {
Expand Down Expand Up @@ -179,4 +180,16 @@ describe('lint', () => {

expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(`Array []`);
});

it('detect OpenAPI should throw an error when version is not string', () => {
const testDocument = parseYamlToDocument(
outdent`
openapi: 3.0
`,
'',
);
expect(() => detectOpenAPI(testDocument.parsed)).toThrow(
`Invalid OpenAPI version: should be a string but got "number"`,
);
});
});
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { RedoclyClient } from '../src/redocly';
import { RedoclyClient } from '../redocly';

describe.skip('login', () => {
it('should call login with setAccessTokens function', async () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { normalizeVisitors, VisitorLevelContext } from '../src/visitors';
import { Oas3RuleSet } from '../src/oas-types';
import { Oas3Types } from '../src/types/oas3';
import { normalizeTypes } from '../src/types';
import { normalizeVisitors, VisitorLevelContext } from '../visitors';
import { Oas3RuleSet } from '../oas-types';
import { Oas3Types } from '../types/oas3';
import { normalizeTypes } from '../types';

describe('Normalize visitors', () => {
it('should work correctly for single rule', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import outdent from 'outdent';
import { parseYamlToDocument } from './utils';
import { parseRef, refBaseName } from '../src/ref-utils';
import { lintDocument } from '../src/lint';
import { LintConfig } from '../src/config';
import { BaseResolver } from '../src/resolve';
import { parseYamlToDocument } from '../../__tests__/utils';
import { parseRef, refBaseName } from '../ref-utils';
import { lintDocument } from '../lint';
import { LintConfig } from '../config';
import { BaseResolver } from '../resolve';

describe('ref-utils', () => {
it(`should unescape refs with '/'`, () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { outdent } from 'outdent';

import { resolveDocument, BaseResolver } from '../src/resolve';
import { parseYamlToDocument } from './utils';
import { Oas3Types } from '../src/types/oas3';
import { normalizeTypes } from '../src/types';
import { resolveDocument, BaseResolver } from '../resolve';
import { parseYamlToDocument } from '../../__tests__/utils';
import { Oas3Types } from '../types/oas3';
import { normalizeTypes } from '../types';

describe('Resolve http-headers', () => {
it('should use matching http-headers', async () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { outdent } from 'outdent';
import * as path from 'path';

import { resolveDocument, BaseResolver, Document } from '../src/resolve';
import { parseYamlToDocument } from './utils';
import { Oas3Types } from '../src/types/oas3';
import { normalizeTypes } from '../src/types';
import { resolveDocument, BaseResolver, Document } from '../resolve';
import { parseYamlToDocument } from '../../__tests__/utils';
import { Oas3Types } from '../types/oas3';
import { normalizeTypes } from '../types';

describe('collect refs', () => {
it('should resolve local refs', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import outdent from 'outdent';
import each from 'jest-each';
import * as path from 'path';

import { lintDocument } from '../src/lint';
import { lintDocument } from '../lint';

import { parseYamlToDocument, replaceSourceWithRef, makeConfigForRuleset } from './utils';
import { BaseResolver, Document } from '../src/resolve';
import { listOf } from '../src/types';
import { Oas3RuleSet } from '../src/oas-types';
import { parseYamlToDocument, replaceSourceWithRef, makeConfigForRuleset } from '../../__tests__/utils';
import { BaseResolver, Document } from '../resolve';
import { listOf } from '../types';
import { Oas3RuleSet } from '../oas-types';

describe('walk order', () => {
it('should run visitors', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ describe('resolveLint', () => {
const lintConfig = {
// This points to ./fixtures/resolve-remote-configs/remote-config.yaml
extends: [
'https://raw.githubusercontent.com/Redocly/openapi-cli/master/packages/core/src/config/__tests__/fixtures/resolve-remote-configs/remote-config.yaml',
'https://raw.githubusercontent.com/Redocly/redocly-cli/master/packages/core/src/config/__tests__/fixtures/resolve-remote-configs/remote-config.yaml',
],
};

Expand Down