From 0fe86542a189c55e3f993017113cf9ab20885320 Mon Sep 17 00:00:00 2001 From: Collin Duncan <3679940+cgduncan7@users.noreply.github.com> Date: Sun, 27 Nov 2022 16:14:56 +0100 Subject: [PATCH] Splitting tests into unit and integration tests --- package.json | 6 ++++-- tests/integration/index.test.ts | 5 +++++ .../common/__snapshots__/scheduler.test.ts.snap | 0 tests/{ => unit}/common/logger.test.ts | 2 +- tests/{ => unit}/common/password.test.ts | 2 +- tests/{ => unit}/common/request.test.ts | 2 +- tests/{ => unit}/common/reservation.test.ts | 2 +- tests/{ => unit}/common/scheduler.test.ts | 8 ++++---- tests/{ => unit}/server/index.test.ts | 6 +++--- 9 files changed, 20 insertions(+), 13 deletions(-) create mode 100644 tests/integration/index.test.ts rename tests/{ => unit}/common/__snapshots__/scheduler.test.ts.snap (100%) rename tests/{ => unit}/common/logger.test.ts (97%) rename tests/{ => unit}/common/password.test.ts (93%) rename tests/{ => unit}/common/request.test.ts (98%) rename tests/{ => unit}/common/reservation.test.ts (96%) rename tests/{ => unit}/common/scheduler.test.ts (89%) rename tests/{ => unit}/server/index.test.ts (93%) diff --git a/package.json b/package.json index 03a2b95..17e470a 100644 --- a/package.json +++ b/package.json @@ -11,9 +11,11 @@ "preinstall": "export CXX=g++-12", "clean": "rm -r ./dist || true", "build": "rollup -c src/server/rollup.config.js", - "test": "jest", + "test:unit": "jest tests/unit/*", + "test:unit:clean": "npm run test:clear-cache && npm run test:unit", + "test:integration": "jest tests/integration/*", + "test:integration:clean": "npm run test:clear-cache && npm run test:integration", "test:clear-cache": "jest --clearCache", - "test:clean": "npm run test:clear-cache && npm run test", "lint": "eslint src/ --ext ts", "prettier": "prettier src tests -w", "local": "npx ts-node src/local.ts", diff --git a/tests/integration/index.test.ts b/tests/integration/index.test.ts new file mode 100644 index 0000000..1d9d203 --- /dev/null +++ b/tests/integration/index.test.ts @@ -0,0 +1,5 @@ +describe('failure', () => { + test('should fail', () => { + expect(true).toBeFalsy() + }) +}) \ No newline at end of file diff --git a/tests/common/__snapshots__/scheduler.test.ts.snap b/tests/unit/common/__snapshots__/scheduler.test.ts.snap similarity index 100% rename from tests/common/__snapshots__/scheduler.test.ts.snap rename to tests/unit/common/__snapshots__/scheduler.test.ts.snap diff --git a/tests/common/logger.test.ts b/tests/unit/common/logger.test.ts similarity index 97% rename from tests/common/logger.test.ts rename to tests/unit/common/logger.test.ts index 10a849a..bf53c11 100644 --- a/tests/common/logger.test.ts +++ b/tests/unit/common/logger.test.ts @@ -1,4 +1,4 @@ -import { Logger, LogLevel } from '../../src/common/logger' +import { Logger, LogLevel } from '../../../src/common/logger' describe('Logger', () => { beforeEach(() => { diff --git a/tests/common/password.test.ts b/tests/unit/common/password.test.ts similarity index 93% rename from tests/common/password.test.ts rename to tests/unit/common/password.test.ts index 88bd728..1237ffd 100644 --- a/tests/common/password.test.ts +++ b/tests/unit/common/password.test.ts @@ -1,4 +1,4 @@ -import * as password from '../../src/common/password' +import * as password from '../../../src/common/password' describe('password', () => { describe('generateSalt', () => { diff --git a/tests/common/request.test.ts b/tests/unit/common/request.test.ts similarity index 98% rename from tests/common/request.test.ts rename to tests/unit/common/request.test.ts index c838a79..8575fd2 100644 --- a/tests/common/request.test.ts +++ b/tests/unit/common/request.test.ts @@ -3,7 +3,7 @@ import dayjs from 'dayjs' import { validateJSONRequest, ValidationError, -} from '../../src/common/request' +} from '../../../src/common/request' describe('request', () => { const testDate = dayjs().add(1, 'day') diff --git a/tests/common/reservation.test.ts b/tests/unit/common/reservation.test.ts similarity index 96% rename from tests/common/reservation.test.ts rename to tests/unit/common/reservation.test.ts index c7ccc76..15d10e9 100644 --- a/tests/common/reservation.test.ts +++ b/tests/unit/common/reservation.test.ts @@ -1,5 +1,5 @@ import dayjs, { Dayjs } from 'dayjs' -import { DateRange, Reservation } from '../../src/common/reservation' +import { DateRange, Reservation } from '../../../src/common/reservation' describe('Reservation', () => { test('will create correct possible dates', () => { diff --git a/tests/common/scheduler.test.ts b/tests/unit/common/scheduler.test.ts similarity index 89% rename from tests/common/scheduler.test.ts rename to tests/unit/common/scheduler.test.ts index a4b6aeb..e9c9842 100644 --- a/tests/common/scheduler.test.ts +++ b/tests/unit/common/scheduler.test.ts @@ -1,9 +1,9 @@ import dayjs from 'dayjs' -import { ValidationError, ValidationErrorCode } from '../../src/common/request' -import { Reservation } from '../../src/common/reservation' -import { work, SchedulerInput } from '../../src/common/scheduler' +import { ValidationError, ValidationErrorCode } from '../../../src/common/request' +import { Reservation } from '../../../src/common/reservation' +import { work, SchedulerInput } from '../../../src/common/scheduler' -jest.mock('../../src/common/logger') +jest.mock('../../../src/common/logger') jest.useFakeTimers().setSystemTime(new Date('2022-01-01')) describe('scheduler', () => { diff --git a/tests/server/index.test.ts b/tests/unit/server/index.test.ts similarity index 93% rename from tests/server/index.test.ts rename to tests/unit/server/index.test.ts index fab034c..608baaf 100644 --- a/tests/server/index.test.ts +++ b/tests/unit/server/index.test.ts @@ -1,7 +1,7 @@ import axios from 'axios' -import server from '../../src/server/index' -import * as scheduler from '../../src/common/scheduler' -import * as utils from '../../src/server/utils' +import server from '../../../src/server/index' +import * as scheduler from '../../../src/common/scheduler' +import * as utils from '../../../src/server/utils' const port = Math.round(Math.random() * 50000 + 10000) const baseUrl = `http://localhost:${port}`