Skip to content
This repository has been archived by the owner on Jul 4, 2023. It is now read-only.

Commit

Permalink
Merge remote-tracking branch 'origin/master' into update-alpha
Browse files Browse the repository at this point in the history
  • Loading branch information
tamj0rd2 committed Sep 24, 2020
2 parents 1a2bc15 + d658f60 commit d5e25e8
Show file tree
Hide file tree
Showing 22 changed files with 3,293 additions and 951 deletions.
6 changes: 3 additions & 3 deletions .dependabot/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: 1
update_configs:
- package_manager: "javascript"
directory: "/"
update_schedule: "live"
update_schedule: "daily"
ignored_updates:
- match:
dependency_name: "@types/node"
Expand All @@ -14,7 +14,7 @@ update_configs:

- package_manager: "javascript"
directory: "/black-box-tests/pre-release"
update_schedule: "live"
update_schedule: "daily"
ignored_updates:
- match:
dependency_name: "@types/node"
Expand All @@ -26,7 +26,7 @@ update_configs:

- package_manager: "docker"
directory: "/"
update_schedule: "live"
update_schedule: "daily"
ignored_updates:
- match:
dependency_name: "node"
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM node:12.16.2-alpine as base
FROM node:12.18.4-alpine as base

RUN apk add --no-cache bash
RUN apk add --no-cache curl
Expand Down
16 changes: 16 additions & 0 deletions black-box-tests/acceptance/__snapshots__/generate.spec.ts.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`ncdc generate can generate multiple configs: toMatchStrippedSnapshot 1`] = `
"info: JSON schemas have been written to disk
"
`;

exports[`ncdc generate can run the generate command with noEmit false and composite true: toMatchStrippedSnapshot 1`] = `
"info: JSON schemas have been written to disk
"
`;

exports[`ncdc generate can run the generate command: toMatchStrippedSnapshot 1`] = `
"info: JSON schemas have been written to disk
"
`;
842 changes: 842 additions & 0 deletions black-box-tests/acceptance/__snapshots__/serve.spec.ts.snap

Large diffs are not rendered by default.

40 changes: 40 additions & 0 deletions black-box-tests/acceptance/__snapshots__/test.spec.ts.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`ncdc test can run the test command: toMatchStrippedSnapshot 1`] = `
"info: PASSED: Shorts - http://localhost:5000/api/resource
"
`;

exports[`ncdc test can test endpoints that return json: toMatchStrippedSnapshot 1`] = `
"info: PASSED: Hello - http://localhost:5000/api/resource
"
`;

exports[`ncdc test does not break when using a rate limit: toMatchStrippedSnapshot 1`] = `
"info: PASSED: Shorts - http://localhost:5000/api/resource
"
`;

exports[`ncdc test gives back a useful error message when a type does not exist on the FS: toMatchStrippedSnapshot 1`] = `
"Code: 1 | Signal: null | Output:
error: An error occurred while validating a fixture within /test-environment/config.yml:
ENOENT: no such file or directory, open '/test-environment/json-schemas/Hello.json'
"
`;

exports[`ncdc test gives back a useful message when a configured body does not match the real response: toMatchStrippedSnapshot 1`] = `
"Code: 1 | Signal: null | Output:
error: FAILED: Hello - http://localhost:5000/api/resource
The response body was not deeply equal to your configured fixture
Received:
{ hello: 123 }
error: Not all tests passed
"
`;

exports[`ncdc test passes even if a request or response has additional properties: toMatchStrippedSnapshot 1`] = `
"info: PASSED: lel - http://localhost:5000/api/resource
"
`;
13 changes: 8 additions & 5 deletions black-box-tests/acceptance/generate.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import strip from 'strip-ansi'
import { runGenerateCommand } from '~shared/generate-wrapper'
import { ConfigWrapper, TEST_ENV, TYPES_FILE } from '~shared/config-wrapper'
import { ConfigBuilder } from '~shared/config-builder'
import { writeFileSync } from 'fs'
import './jest-extensions'

jest.useRealTimers()
jest.setTimeout(10000)
Expand All @@ -23,7 +23,8 @@ describe('ncdc generate', () => {

const output = await runGenerateCommand()

expect(strip(output)).toContain(`JSON schemas have been written to disk`)
expect(output).toContain(`JSON schemas have been written to disk`)
expect(output).toMatchStrippedSnapshot()
})

// TODO: now that multiple configs are a thing, this whole config wrapping thing definitely needs a redo
Expand Down Expand Up @@ -54,7 +55,8 @@ describe('ncdc generate', () => {

const output = await runGenerateCommand(config2Path)

expect(strip(output)).toContain(`JSON schemas have been written to disk`)
expect(output).toContain(`JSON schemas have been written to disk`)
expect(output).toMatchStrippedSnapshot()
})

it('handles a case where a type does not exist gracefully', async () => {
Expand All @@ -71,7 +73,7 @@ describe('ncdc generate', () => {

const output = await runGenerateCommand()

expect(strip(output)).toContain('error: Could not find type: RTypeDelta')
expect(output).toContain('error: Could not find type: RTypeDelta')
})

it('can run the generate command with noEmit false and composite true', async () => {
Expand All @@ -98,6 +100,7 @@ describe('ncdc generate', () => {

const output = await runGenerateCommand()

expect(strip(output)).toContain(`JSON schemas have been written to disk`)
expect(output).toContain(`JSON schemas have been written to disk`)
expect(output).toMatchStrippedSnapshot()
})
})
29 changes: 29 additions & 0 deletions black-box-tests/acceptance/jest-extensions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import strip from 'strip-ansi'
import { toMatchSnapshot } from 'jest-snapshot'

// eslint-disable-next-line @typescript-eslint/no-unused-vars
declare global {
// eslint-disable-next-line @typescript-eslint/no-namespace
namespace jest {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
interface Matchers<R> {
toMatchStrippedSnapshot(): R
}
}
}

expect.extend({
toMatchStrippedSnapshot(received) {
const content = strip(received)
.split('\n')
.map((line) => {
const filePathRegex = /\/(?:.*\/)+test-environment/i
return line.replace(filePathRegex, '/test-environment')
})
.join('\n')

// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore do not know how to fix this "this" type mismatch
return toMatchSnapshot.call(this, content, 'toMatchStrippedSnapshot')
},
})
Loading

0 comments on commit d5e25e8

Please sign in to comment.