Skip to content

Commit

Permalink
build: migrate nx
Browse files Browse the repository at this point in the history
  • Loading branch information
aaron-plahn committed Sep 27, 2022
1 parent 11b19d7 commit 270eeaf
Show file tree
Hide file tree
Showing 57 changed files with 13,528 additions and 14,605 deletions.
47 changes: 22 additions & 25 deletions apps/api/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,27 +1,24 @@
{
"extends": ["../../.eslintrc.json"],
"ignorePatterns": ["!**/*"],
"overrides": [
{
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
"rules": {
// TODO: Re-enable this
"@nrwl/nx/enforce-module-boundaries": [2],
// When dealing generically with class instances we need object as a type
"@typescript-eslint/ban-types": [0],
"@typescript-eslint/no-unused-vars": [2]
}
},
{
"files": ["*.ts", "*.tsx"],
"rules": {
// TODO: Re-enable this
"@nrwl/nx/enforce-module-boundaries": [2]
}
},
{
"files": ["*.js", "*.jsx"],
"rules": {}
}
]
"extends": ["../../.eslintrc.json"],
"ignorePatterns": ["!**/*"],
"overrides": [
{
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
"rules": {
"@nrwl/nx/enforce-module-boundaries": [2],
"@typescript-eslint/ban-types": [0],
"@typescript-eslint/no-unused-vars": [2]
}
},
{
"files": ["*.ts", "*.tsx"],
"rules": {
"@nrwl/nx/enforce-module-boundaries": [2]
}
},
{
"files": ["*.js", "*.jsx"],
"rules": {}
}
]
}
3 changes: 2 additions & 1 deletion apps/api/jest.config.js → apps/api/jest.config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
module.exports = {
/* eslint-disable */
export default {
displayName: 'api',
preset: '../../jest.preset.js',
globals: {
Expand Down
21 changes: 12 additions & 9 deletions apps/api/project.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"root": "apps/api",
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"sourceRoot": "apps/api/src",
"projectType": "application",
"targets": {
Expand All @@ -11,12 +11,14 @@
"main": "apps/api/src/main.ts",
"tsConfig": "apps/api/tsconfig.app.json",
"assets": ["apps/api/src/assets"],
"tsPlugins": [{
"name": "@nestjs/swagger/plugin",
"options": {
"dtoFilenameSuffix": [".entity.ts",".view-model.ts"]
"tsPlugins": [
{
"name": "@nestjs/swagger/plugin",
"options": {
"dtoFilenameSuffix": [".entity.ts", ".view-model.ts"]
}
}
}]
]
},
"configurations": {
"production": {
Expand All @@ -33,7 +35,7 @@
}
},
"serve": {
"executor": "@nrwl/node:execute",
"executor": "@nrwl/node:node",
"options": {
"buildTarget": "api:build"
}
Expand All @@ -42,13 +44,14 @@
"executor": "@nrwl/linter:eslint",
"options": {
"lintFilePatterns": ["apps/api/**/*.ts"]
}
},
"outputs": ["{options.outputFile}"]
},
"test": {
"executor": "@nrwl/jest:jest",
"outputs": ["coverage/apps/api"],
"options": {
"jestConfig": "apps/api/jest.config.js",
"jestConfig": "apps/api/jest.config.ts",
"passWithNoTests": true
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ exports[`The Command Controller when the payload is valid should persist the res
Array [
Object {
"meta": Object {
"dateCreated": 1586044800000,
"dateCreated": 1664237194356,
"id": "41fb2d7f-c483-4e09-a1f0-e9909a6b0005",
"userId": "1",
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { CreateSong } from '../../../domain/models/song/commands/create-song.com
import { CreateSongCommandHandler } from '../../../domain/models/song/commands/create-song.command-handler';
import { Song } from '../../../domain/models/song/song.entity';
import { CoscradUserWithGroups } from '../../../domain/models/user-management/user/entities/user/coscrad-user-with-groups';
import { buildFakeTimersConfig } from '../../../domain/models/__tests__/utilities/buildFakeTimersConfig';
import { ResourceType } from '../../../domain/types/ResourceType';
import buildInMemorySnapshot from '../../../domain/utilities/buildInMemorySnapshot';
import getValidAggregateInstanceForTest from '../../../domain/__tests__/utilities/getValidAggregateInstanceForTest';
Expand Down Expand Up @@ -71,7 +72,7 @@ describe('The Command Controller', () => {
new CreateSongCommandHandler(testRepositoryProvider, idManager)
);

jest.useFakeTimers().setSystemTime(new Date('2020-04-05'));
jest.useFakeTimers(buildFakeTimersConfig());
});

beforeEach(async () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { dummyDateNow } from './dummyDateNow';

/**
* We build this so not to share references via the config object.
*/
export const buildFakeTimersConfig = (): FakeTimersConfig => ({
now: dummyDateNow,
});
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const dummyDateNow = 1664237194356;
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ CoscradUserGroup {
"eventHistory": Array [
Object {
"meta": Object {
"dateCreated": 1586044800000,
"dateCreated": 1664237194356,
"id": "41fb2d7f-c483-4e09-a1f0-e9909a6b0002",
"userId": "system4d-3b7d-4bad-9bdd-2b0d70userid",
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { CommandHandlerService, FluxStandardAction } from '@coscrad/commands';
import { INestApplication } from '@nestjs/common';
import setUpIntegrationTest from '../../../../../../app/controllers/__tests__/setUpIntegrationTest';
import { assertExternalStateError } from '../../../../../../domain/models/__tests__/command-helpers/assert-external-state-error';
import { buildFakeTimersConfig } from '../../../../../../domain/models/__tests__/utilities/buildFakeTimersConfig';
import { InternalError } from '../../../../../../lib/errors/InternalError';
import { NotAvailable } from '../../../../../../lib/types/not-available';
import generateDatabaseNameForTestSuite from '../../../../../../persistence/repositories/__tests__/generateDatabaseNameForTestSuite';
Expand All @@ -22,6 +23,7 @@ import { generateCommandFuzzTestCases } from '../../../../__tests__/command-help
import { CommandAssertionDependencies } from '../../../../__tests__/command-helpers/types/CommandAssertionDependencies';
import buildDummyUuid from '../../../../__tests__/utilities/buildDummyUuid';
import { dummySystemUserId } from '../../../../__tests__/utilities/dummySystemUserId';
import { dummyUuid } from '../../../../__tests__/utilities/dummyUuid';
import { CoscradUserGroup } from '../../entities/coscrad-user-group.entity';
import { UserGroupLabelAlreadyInUseError } from '../../errors/external-state-errors/UserGroupLabelAlreadyInUseError';
import { CreateGroup } from './create-group.command';
Expand All @@ -47,7 +49,7 @@ const buildInvalidFSA = (id, payloadOverrides) => fsaFactory.build(id, payloadOv

const existingUserGroupDto: DTO<CoscradUserGroup> = {
type: AggregateType.userGroup,
id: buildDummyUuid(),
id: dummyUuid,
label: 'existing users',
description: 'this group already exists before running the command',
userIds: [],
Expand Down Expand Up @@ -86,7 +88,7 @@ describe('CreateGroup', () => {
commandHandlerService,
};

jest.useFakeTimers().setSystemTime(new Date('2020-04-05'));
jest.useFakeTimers(buildFakeTimersConfig());
});

afterAll(async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ import {
} from '../../../domain/models/context/edge-connection.entity';
import { PageRangeContext } from '../../../domain/models/context/page-range-context/page-range.context.entity';
import { EdgeConnectionContextType } from '../../../domain/models/context/types/EdgeConnectionContextType';
import { Resource } from '../../../domain/models/resource.entity';
import { AggregateType } from '../../../domain/types/AggregateType';
import { HasAggregateId } from '../../../domain/types/HasAggregateId';
import { ResourceType } from '../../../domain/types/ResourceType';
import buildTestData from '../../../test-data/buildTestData';
import { DTO } from '../../../types/DTO';
import { ArangoEdgeDocument } from '../types/ArangoEdgeDocument';
import mapArangoEdgeDocumentToEdgeConnectionDTO from './mapArangoEdgeDocumentToEdgeConnectionDTO';
import mapDatabaseDTOToEntityDTO from './mapDatabaseDocumentToAggregateDTO';
import mapDatabaseDTOToAggregateDTO from './mapDatabaseDocumentToAggregateDTO';
import mapEdgeConnectionDTOToArangoEdgeDocument from './mapEdgeConnectionDTOToArangoEdgeDocument';
import mapEntityDTOToDatabaseDTO, { DatabaseDTO } from './mapEntityDTOToDatabaseDTO';

Expand Down Expand Up @@ -53,7 +54,7 @@ const edgeConnections: DTO<EdgeConnection>[] = [
];

const resourceDTOs = Object.values(testData.resources).flatMap((instances) =>
instances.map((instance) => instance.toDTO())
instances.map((instance: Resource) => instance.toDTO())
);

const edgeDocumentToDTOTestCase: TestCase<ArangoEdgeDocument, DTO<EdgeConnection>> = {
Expand All @@ -75,7 +76,7 @@ const resourceDocumentToDTOTestCase: TestCase<DatabaseDTO, DTO<HasAggregateId>>
description: 'when mapping an Arango resource document to a Resource DTO',
forwardLabel: 'document => DTO',
reverseLabel: 'DTO => document',
forward: mapDatabaseDTOToEntityDTO,
forward: mapDatabaseDTOToAggregateDTO,
reverse: mapEntityDTOToDatabaseDTO,
/**
* Let's omit this direction. Building up dummy documents requires either
Expand All @@ -94,7 +95,10 @@ testCases.forEach(
describe(`when mapping: ${forwardLabel}`, () => {
inputs.forEach((input) =>
it('applying the forward then reverse mapping should leave the input unchanged', () => {
const result = reverse(forward(input));
const forwardResult = forward(input);

// @ts-expect-error TODO fix type error
const result = reverse(forwardResult);

expect(result).toBe(input);
})
Expand All @@ -104,6 +108,7 @@ testCases.forEach(
describe(`when mapping: ${reverseLabel}`, () => {
outputs.forEach((output) =>
it('applying the reverse then forward mapping should leave the input unchanged', () => {
// @ts-expect-error TODO fix type error
const result = forward(reverse(output));

expect(result).toEqual(output);
Expand Down
23 changes: 11 additions & 12 deletions apps/api/tsconfig.app.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "../../dist/out-tsc",
"module": "commonjs",
"types": ["node"],
"emitDecoratorMetadata": true,
"target": "es2019",
"lib": ["ES2019"]
},
"exclude": ["**/*.spec.ts","**/*.test.ts","**/*.d.ts","**/__tests__/*"],
"include": ["**/*.ts"],

"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "../../dist/out-tsc",
"module": "commonjs",
"types": ["node"],
"emitDecoratorMetadata": true,
"target": "es2019",
"lib": ["ES2019"]
},
"exclude": ["**/*.spec.ts", "**/*.test.ts", "**/*.d.ts", "**/__tests__/*", "jest.config.ts"],
"include": ["**/*.ts"]
}
14 changes: 7 additions & 7 deletions apps/api/tsconfig.spec.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "../../dist/out-tsc",
"module": "commonjs",
"types": ["jest", "node"]
},
"include": ["**/*.spec.ts", "**/*.test.ts","**/*.d.ts","**/__tests__/*"]
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "../../dist/out-tsc",
"module": "commonjs",
"types": ["jest", "node"]
},
"include": ["**/*.spec.ts", "**/*.test.ts", "**/*.d.ts", "**/__tests__/*"]
}
16 changes: 8 additions & 8 deletions apps/coscrad-frontend-e2e/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"extends": ["plugin:cypress/recommended", "../../.eslintrc.json"],
"ignorePatterns": ["!**/*"],
"overrides": [
{
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
"rules": {}
}
]
"extends": ["plugin:cypress/recommended", "../../.eslintrc.json"],
"ignorePatterns": ["!**/*"],
"overrides": [
{
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
"rules": {}
}
]
}
2 changes: 1 addition & 1 deletion apps/coscrad-frontend-e2e/project.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"root": "apps/coscrad-frontend-e2e",
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"sourceRoot": "apps/coscrad-frontend-e2e/src",
"projectType": "application",
"targets": {
Expand Down
32 changes: 16 additions & 16 deletions apps/coscrad-frontend/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
{
"extends": ["plugin:@nrwl/nx/react", "../../.eslintrc.json"],
"ignorePatterns": ["!**/*"],
"overrides": [
{
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
"rules": {}
},
{
"files": ["*.ts", "*.tsx"],
"rules": {}
},
{
"files": ["*.js", "*.jsx"],
"rules": {}
}
]
"extends": ["plugin:@nrwl/nx/react", "../../.eslintrc.json"],
"ignorePatterns": ["!**/*"],
"overrides": [
{
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
"rules": {}
},
{
"files": ["*.ts", "*.tsx"],
"rules": {}
},
{
"files": ["*.js", "*.jsx"],
"rules": {}
}
]
}
10 changes: 0 additions & 10 deletions apps/coscrad-frontend/jest.config.js

This file was deleted.

11 changes: 11 additions & 0 deletions apps/coscrad-frontend/jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/* eslint-disable */
export default {
displayName: 'coscrad-frontend',
preset: '../../jest.preset.js',
transform: {
'^(?!.*\\.(js|jsx|ts|tsx|css|json)$)': '@nrwl/react/plugins/jest',
'^.+\\.[tj]sx?$': ['babel-jest', { presets: ['@nrwl/react/babel'] }],
},
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx'],
coverageDirectory: '../../coverage/apps/coscrad-frontend',
};
Loading

0 comments on commit 270eeaf

Please sign in to comment.