Move unit tests to files they apply to (#15130)

* Move unit tests to files they apply to

* Remove tests root
This commit is contained in:
Rijk van Zanten
2022-08-17 16:01:16 -04:00
committed by GitHub
parent 122f8cfed0
commit 19ddd89d8d
27 changed files with 20 additions and 20 deletions

View File

@@ -4,7 +4,7 @@ require('dotenv').config();
module.exports = {
...base,
roots: ['<rootDir>/tests', '<rootDir>/src'],
roots: ['<rootDir>/src'],
verbose: true,
setupFiles: ['dotenv/config'],
collectCoverageFrom: ['src/**/*.ts'],

View File

@@ -1,4 +1,4 @@
import { Snapshot, SnapshotField, SnapshotRelation } from '../../src/types';
import { Snapshot, SnapshotField, SnapshotRelation } from '../types';
export const snapshotBeforeCreateCollection: Snapshot = {
version: 1,

View File

@@ -1,6 +1,6 @@
import { Command } from 'commander';
import { Extension, HookConfig } from '@directus/shared/types';
import { createCli } from '../../src/cli/index';
import { createCli } from './index';
jest.mock('../../src/env', () => ({
...jest.requireActual('../../src/env').default,

View File

@@ -4,8 +4,8 @@ jest.mock('../../src/cache');
jest.mock('../../src/database');
jest.mock('../../src/utils/validate-env');
import { multipartHandler } from '../../src/controllers/files';
import { InvalidPayloadException } from '../../src/exceptions/invalid-payload';
import { multipartHandler } from './files';
import { InvalidPayloadException } from '../exceptions/invalid-payload';
import { PassThrough } from 'stream';
import FormData from 'form-data';

View File

@@ -1,6 +1,6 @@
import knex, { Knex } from 'knex';
import { getTracker, MockClient, Tracker } from 'knex-mock-client';
import run from '../../../src/database/migrations/run';
import run from './run';
describe('run', () => {
let db: jest.Mocked<Knex>;

View File

@@ -1,11 +1,11 @@
// @ts-nocheck
import jwt from 'jsonwebtoken';
import getDatabase from '../../src/database';
import emitter from '../../src/emitter';
import env from '../../src/env';
import { InvalidCredentialsException } from '../../src/exceptions';
import { handler } from '../../src/middleware/authenticate';
import getDatabase from '../database';
import emitter from '../emitter';
import env from '../env';
import { InvalidCredentialsException } from '../exceptions';
import { handler } from './authenticate';
import '../../src/types/express.d.ts';
jest.mock('../../src/database');

View File

@@ -1,7 +1,7 @@
import exifr from 'exifr';
import knex, { Knex } from 'knex';
import { MockClient, Tracker, getTracker } from 'knex-mock-client';
import { FilesService } from '../../src/services';
import { FilesService } from '.';
jest.mock('exifr');
jest.mock('../../src/database/index', () => {

View File

@@ -2,8 +2,8 @@ import { Query } from '@directus/shared/types';
import knex, { Knex } from 'knex';
import { getTracker, MockClient, Tracker } from 'knex-mock-client';
import { ItemsService } from '../../src/services';
import { sqlFieldFormatter, sqlFieldList } from '../__test-utils__/items-utils';
import { systemSchema, userSchema } from '../__test-utils__/schemas';
import { sqlFieldFormatter, sqlFieldList } from '../__utils__/items-utils';
import { systemSchema, userSchema } from '../__utils__/schemas';
import { cloneDeep } from 'lodash';
jest.mock('../../src/database/index', () => {

View File

@@ -1,17 +1,17 @@
import knex, { Knex } from 'knex';
import { getTracker, MockClient, Tracker } from 'knex-mock-client';
import { snapshotApplyTestSchema } from '../__test-utils__/schemas';
import { snapshotApplyTestSchema } from '../__utils__/schemas';
import { CollectionsService, FieldsService } from '../../src/services';
import { applySnapshot } from '../../src/utils/apply-snapshot';
import * as getSchema from '../../src/utils/get-schema';
import { CollectionsService, FieldsService } from '../services';
import { applySnapshot } from './apply-snapshot';
import * as getSchema from './get-schema';
import {
snapshotBeforeCreateCollection,
snapshotCreateCollection,
snapshotCreateCollectionNotNested,
snapshotBeforeDeleteCollection,
} from '../__test-utils__/snapshots';
import { Snapshot } from '../../src/types';
} from '../__utils__/snapshots';
import { Snapshot } from '../types';
jest.mock('../../src/database/index', () => {
return {