Skip to content

Commit

Permalink
Colocate test files with source files
Browse files Browse the repository at this point in the history
  • Loading branch information
jstayton committed Jun 22, 2021
1 parent cda077a commit aa42465
Show file tree
Hide file tree
Showing 23 changed files with 66 additions and 67 deletions.
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,8 @@ $ npm install

### Tests

[Jest](https://jestjs.io/) is our testing framework of choice, with
file-specific tests contained in the `test/src` directory. We strive for 100%
code coverage.
[Jest](https://jestjs.io/) is our testing framework of choice. We strive for
100% code coverage.

To run the tests:

Expand Down
2 changes: 1 addition & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ module.exports = {
},
],
],
testMatch: ['**/test/src/**/*.js'],
testPathIgnorePatterns: ['/node_modules/', '/test/'],
}
4 changes: 2 additions & 2 deletions test/src/adapters/base.js → src/adapters/base.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const BaseAdapter = require('../../../src/adapters/base')
const NotImplementedError = require('../../../src/errors/not_implemented')
const BaseAdapter = require('./base')
const NotImplementedError = require('../errors/not_implemented')

describe('constructor', () => {
test('creates an instance of the validator, calls `defineValidation`', () => {
Expand Down
4 changes: 2 additions & 2 deletions test/src/adapters/knex.js → src/adapters/knex.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const knex = require('knex')({ client: 'pg' })

const KnexAdapter = require('../../../src/adapters/knex')
const ValidationError = require('../../../src/errors/validation')
const KnexAdapter = require('./knex')
const ValidationError = require('../errors/validation')

describe('filter', () => {
test('uses `field` for the column, not `name`', () => {
Expand Down
2 changes: 1 addition & 1 deletion test/src/config.js → src/config.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const Config = require('../../src/config')
const Config = require('./config')

describe('constructor', () => {
test('accepts an object of values to set', () => {
Expand Down
2 changes: 1 addition & 1 deletion test/src/errors/base.js → src/errors/base.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const BaseError = require('../../../src/errors/base')
const BaseError = require('./base')

test('extends Error', () => {
expect(new BaseError('test')).toBeInstanceOf(Error)
Expand Down
12 changes: 6 additions & 6 deletions test/src/index.js → src/index.test.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
const knex = require('knex')({ client: 'pg' })

const Config = require('../../src/config')
const EmptyQuerier = require('../queriers/empty')
const NotImplementedError = require('../../src/errors/not_implemented')
const QueryQL = require('../../src')
const TestQuerier = require('../queriers/test')
const ValidationError = require('../../src/errors/validation')
const Config = require('./config')
const EmptyQuerier = require('../test/queriers/empty')
const NotImplementedError = require('./errors/not_implemented')
const QueryQL = require('.')
const TestQuerier = require('../test/queriers/test')
const ValidationError = require('./errors/validation')

describe('constructor', () => {
test('accepts a query to set', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
const knex = require('knex')({ client: 'pg' })

const BaseOrchestrator = require('../../../src/orchestrators/base')
const NotImplementedError = require('../../../src/errors/not_implemented')
const TestQuerier = require('../../queriers/test')
const ValidationError = require('../../../src/errors/validation')
const BaseOrchestrator = require('./base')
const NotImplementedError = require('../errors/not_implemented')
const TestQuerier = require('../../test/queriers/test')
const ValidationError = require('../errors/validation')
let buildParser

beforeEach(() => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
const knex = require('knex')({ client: 'pg' })

const EmptyQuerier = require('../../queriers/empty')
const Filterer = require('../../../src/orchestrators/filterer')
const TestQuerier = require('../../queriers/test')
const ValidationError = require('../../../src/errors/validation')
const EmptyQuerier = require('../../test/queriers/empty')
const Filterer = require('./filterer')
const TestQuerier = require('../../test/queriers/test')
const ValidationError = require('../errors/validation')

describe('queryKey', () => {
test('returns the key for filters in the query', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
const knex = require('knex')({ client: 'pg' })

const EmptyQuerier = require('../../queriers/empty')
const Pager = require('../../../src/orchestrators/pager')
const TestQuerier = require('../../queriers/test')
const ValidationError = require('../../../src/errors/validation')
const EmptyQuerier = require('../../test/queriers/empty')
const Pager = require('./pager')
const TestQuerier = require('../../test/queriers/test')
const ValidationError = require('../errors/validation')

describe('queryKey', () => {
test('returns the key for pagination in the query', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
const knex = require('knex')({ client: 'pg' })

const EmptyQuerier = require('../../queriers/empty')
const Sorter = require('../../../src/orchestrators/sorter')
const TestQuerier = require('../../queriers/test')
const ValidationError = require('../../../src/errors/validation')
const EmptyQuerier = require('../../test/queriers/empty')
const Sorter = require('./sorter')
const TestQuerier = require('../../test/queriers/test')
const ValidationError = require('../errors/validation')

describe('queryKey', () => {
test('returns the key for filters in the query', () => {
Expand Down
8 changes: 4 additions & 4 deletions test/src/parsers/base.js → src/parsers/base.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const BaseParser = require('../../../src/parsers/base')
const NotImplementedError = require('../../../src/errors/not_implemented')
const Schema = require('../../../src/schema')
const ValidationError = require('../../../src/errors/validation')
const BaseParser = require('./base')
const NotImplementedError = require('../errors/not_implemented')
const Schema = require('../schema')
const ValidationError = require('../errors/validation')

describe('constructor', () => {
test('accepts a query key to set', () => {
Expand Down
6 changes: 3 additions & 3 deletions test/src/parsers/filter.js → src/parsers/filter.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const FilterParser = require('../../../src/parsers/filter')
const Schema = require('../../../src/schema')
const ValidationError = require('../../../src/errors/validation')
const FilterParser = require('./filter')
const Schema = require('../schema')
const ValidationError = require('../errors/validation')

describe('DEFAULTS', () => {
test('returns `null` as the default name', () => {
Expand Down
6 changes: 3 additions & 3 deletions test/src/parsers/page.js → src/parsers/page.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const PageParser = require('../../../src/parsers/page')
const Schema = require('../../../src/schema')
const ValidationError = require('../../../src/errors/validation')
const PageParser = require('./page')
const Schema = require('../schema')
const ValidationError = require('../errors/validation')

describe('DEFAULTS', () => {
test('returns `20` as the default size', () => {
Expand Down
6 changes: 3 additions & 3 deletions test/src/parsers/sort.js → src/parsers/sort.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const SortParser = require('../../../src/parsers/sort')
const Schema = require('../../../src/schema')
const ValidationError = require('../../../src/errors/validation')
const SortParser = require('./sort')
const Schema = require('../schema')
const ValidationError = require('../errors/validation')

describe('DEFAULTS', () => {
test('returns `null` as the default name', () => {
Expand Down
2 changes: 1 addition & 1 deletion test/src/schema.js → src/schema.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const Schema = require('../../src/schema')
const Schema = require('./schema')

describe('constructor', () => {
test('defaults to no whitelisted filters', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const cacheFunction = require('../../../src/services/cache_function')
const cacheFunction = require('./cache_function')

test('accepts/calls `func` and returns the value', () => {
const value = 'test123'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const flattenMap = require('../../../src/services/flatten_map')
const flattenMap = require('./flatten_map')

test('uses the map key/value as the object key/value by default', () => {
const map = new Map([
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const Joi = require('joi')

const joiValidationErrorConverter = require('../../../src/services/joi_validation_error_converter')
const ValidationError = require('../../../src/errors/validation')
const joiValidationErrorConverter = require('./joi_validation_error_converter')
const ValidationError = require('../errors/validation')

test('prepends optional path prefix to path if path exists', () => {
const { error } = Joi.object()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
const Joi = require('joi')

const AdapterValidator = require('../../../src/validators/adapter')
const FilterParser = require('../../../src/parsers/filter')
const PageParser = require('../../../src/parsers/page')
const Schema = require('../../../src/schema')
const SortParser = require('../../../src/parsers/sort')
const ValidationError = require('../../../src/errors/validation')
const AdapterValidator = require('./adapter')
const FilterParser = require('../parsers/filter')
const PageParser = require('../parsers/page')
const Schema = require('../schema')
const SortParser = require('../parsers/sort')
const ValidationError = require('../errors/validation')

describe('constructor', () => {
test('accepts/calls `defineSchema` and sets the returned value', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const Joi = require('joi')

const ParserValidator = require('../../../src/validators/parser')
const ValidationError = require('../../../src/errors/validation')
const ParserValidator = require('./parser')
const ValidationError = require('../errors/validation')

describe('constructor', () => {
test('accepts/calls `defineSchema` and sets the returned value', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const BaseValidator = require('../../../../src/validators/querier/base')
const NotImplementedError = require('../../../../src/errors/not_implemented')
const ValidationError = require('../../../../src/errors/validation')
const BaseValidator = require('./base')
const NotImplementedError = require('../../errors/not_implemented')
const ValidationError = require('../../errors/validation')

describe('constructor', () => {
test('accepts/calls `defineSchema` and sets the returned value', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
const Joi = require('joi')

const FilterParser = require('../../../../src/parsers/filter')
const JoiValidator = require('../../../../src/validators/querier/joi')
const PageParser = require('../../../../src/parsers/page')
const Schema = require('../../../../src/schema')
const SortParser = require('../../../../src/parsers/sort')
const ValidationError = require('../../../../src/errors/validation')
const FilterParser = require('../../parsers/filter')
const JoiValidator = require('./joi')
const PageParser = require('../../parsers/page')
const Schema = require('../../schema')
const SortParser = require('../../parsers/sort')
const ValidationError = require('../../errors/validation')

describe('constructor', () => {
test('accepts/calls `defineSchema(Joi)` and sets the returned value', () => {
Expand Down

0 comments on commit aa42465

Please sign in to comment.