Skip to content

Commit

Permalink
fix: updated all libraries to their latest versions
Browse files Browse the repository at this point in the history
feat: added proper tooling for usage of scripts

chore: trying to fix tests

chore: looking for openHandles

chore: added new section to display code coverage never completes

chore: try removing fastify

chore: playing around with reporters

chore: testing out if nx is the issue or jest itself

chore: trying to run in band

chore: reverted to old jest version

chore: everything should work

chore: brought back old tests, should still work

chore: some fixes

chore: test to see if integrations still work with caching

chore: now caching cypress binary

chore: final touches
  • Loading branch information
yann510 committed Jan 14, 2022
1 parent 06df447 commit 8146195
Show file tree
Hide file tree
Showing 57 changed files with 29,729 additions and 31,180 deletions.
35 changes: 35 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"root": true,
"ignorePatterns": ["**/*"],
"plugins": ["@nrwl/nx"],
"overrides": [
{
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
"rules": {
"@nrwl/nx/enforce-module-boundaries": [
"error",
{
"enforceBuildableLibDependency": true,
"allow": [],
"depConstraints": [
{
"sourceTag": "*",
"onlyDependOnLibsWithTags": ["*"]
}
]
}
]
}
},
{
"files": ["*.ts", "*.tsx"],
"extends": ["plugin:@nrwl/nx/typescript"],
"rules": {}
},
{
"files": ["*.js", "*.jsx"],
"extends": ["plugin:@nrwl/nx/javascript"],
"rules": {}
}
]
}
2 changes: 0 additions & 2 deletions .github/scripts/get-base.sh

This file was deleted.

2 changes: 0 additions & 2 deletions .github/scripts/get-head.sh

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,9 @@ on:
- master

jobs:
build:
build-test-release:
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [14.13.1]

steps:
- name: Cancel previous runs
uses: styfle/cancel-workflow-action@0.5.0
Expand All @@ -28,17 +24,10 @@ jobs:
with:
fetch-depth: 0

- name: Set head
run: sh .github/scripts/get-head.sh >> $GITHUB_ENV
env:
PR_HEAD: ${{ github.event.pull_request.head.sha }}
MERGE_HEAD: ${{ github.event.after }}

- name: Set base
run: sh .github/scripts/get-base.sh >> $GITHUB_ENV
env:
PR_BASE: ${{ github.event.pull_request.base.sha }}
MERGE_BASE: ${{ github.event.before }}
- name: Derive appropriate SHAs for base and head for `nx affected` commands
uses: nrwl/nx-set-shas@v2
with:
main-branch-name: master

- name: Inject Nx Cloud token
shell: bash
Expand All @@ -50,33 +39,43 @@ jobs:
- name: Setup postgres container
run: docker-compose -f $GITHUB_WORKSPACE/apps/database/postgres/docker-compose.yml up -d

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v2-beta
- name: Setup node.js 14.18.0
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}
node-version: 14.18.0

- name: Cache dependencies
id: cache
uses: actions/cache@v2
with:
path: |
./node_modules
/home/runner/.cache/Cypress
key: modules-${{ hashFiles('package-lock.json') }}

- name: Install npm packages
if: steps.cache.outputs.cache-hit != 'true'
run: npm i

- name: Lint files
run: npm run affected:lint -- --base=$BASE --head=$HEAD
- name: Start api
run: npm run typeorm -- migration:run && npm start api &
env:
TEST: true

- name: Enforce naming conventions
run: npm run lint:file-folder-convention

- name: Build affected apps
run: npm run affected:build -- --base=$BASE --head=$HEAD
- name: Lint affected files
run: npm run affected:lint

- name: Start api
run: npm run typeorm -- migration:run && npm start api &
env:
TEST: true
- name: Build affected apps
run: npm run affected:build

- name: Run tests
run: npm run affected:test -- --base=$BASE --head=$HEAD --code-coverage
- name: Test affected apps
run: npm run affected:test -- --code-coverage

- name: Run e2e tests
run: npm run affected:e2e -- --base=$BASE --head=$HEAD
- name: Test affected apps e2e
run: npm run affected:e2e

- name: Codecov
uses: codecov/codecov-action@v2
Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,6 @@ npm run rename-project -- --organization {YOUR_ORGANIZATION_NAME} --project {YOU

\*Note: I highly recommend that the project name is the same as your git repository.

The file will delete itself once it has been completed.
On completion, you will see the following message:

![project appropriation success](readme-assets/project-appropriation-success.png)
Expand Down
1 change: 1 addition & 0 deletions apps/api/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ module.exports = {
moduleFileExtensions: ["ts", "js", "html"],
coverageDirectory: "../../coverage/apps/api",
coveragePathIgnorePatterns: ["./src/config/"],
testEnvironment: "node",
}
33 changes: 15 additions & 18 deletions apps/api/src/config/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,21 @@ export const configuration = () => ({
...ormConfig,
certificateAuthority: process.env.DATABASE_CA_CERT,
keepConnectionAlive: false,
entities: [Todo],
logging: ["error"],
retries: 1,
retryAttempts: 1,
},
})

export const getOrmConfigFn = async (configService: ConfigService): Promise<TypeOrmModuleOptions> =>
Promise.resolve({
type: "postgres",
host: configService.get("database.host"),
port: configService.get<number>("database.port"),
database: configService.get("database.name"),
username: configService.get("database.username"),
password: configService.get("database.password"),
synchronize: configService.get("database.synchronize"),
keepConnectionAlive: configService.get("database.keepConnectionAlive"),
ssl: configService.get("database.certificateAuthority") ?? false,
entities: configService.get("database.entities"),
logging: configService.get("database.logging"),
retries: configService.get("database.retries"),
})
export const getOrmConfigFn = async (configService: ConfigService): Promise<TypeOrmModuleOptions> => ({
type: "postgres",
host: configService.get("database.host"),
port: configService.get<number>("database.port"),
database: configService.get("database.database"),
username: configService.get("database.username"),
password: configService.get("database.password"),
synchronize: configService.get("database.synchronize"),
keepConnectionAlive: configService.get("database.keepConnectionAlive"),
ssl: configService.get("database.certificateAuthority") ?? false,
entities: [Todo],
logging: ["error"],
retryAttempts: configService.get<number>("database.retryAttempts"),
})
4 changes: 3 additions & 1 deletion apps/api/src/endpoints/health/health.e2e.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ describe("Health", () => {
testingHelper = await new TestingHelper().initializeModuleAndApp("health", [HealthModule])
})

beforeEach(() => testingHelper.reloadFixtures())
afterAll(async () => {
await testingHelper.shutdownServer()
})

describe("GET /health", () => {
it("should return status 200", async () => {
Expand Down
25 changes: 10 additions & 15 deletions apps/api/src/utils/test.ts
Original file line number Diff line number Diff line change
@@ -1,41 +1,35 @@
import fs from "fs"
import path from "path"

import { INestApplication } from "@nestjs/common"
import { DynamicModule } from "@nestjs/common/interfaces/modules/dynamic-module.interface"
import { ForwardReference } from "@nestjs/common/interfaces/modules/forward-reference.interface"
import { ModuleMetadata } from "@nestjs/common/interfaces/modules/module-metadata.interface"
import { Provider } from "@nestjs/common/interfaces/modules/provider.interface"
import { Type } from "@nestjs/common/interfaces/type.interface"
import { FastifyAdapter } from "@nestjs/platform-fastify"
import { FastifyAdapter, NestFastifyApplication } from "@nestjs/platform-fastify"
import { Test, TestingModule } from "@nestjs/testing"
import { Connection, createConnection } from "typeorm"
import { getRepository } from "typeorm"
import { Builder, Loader, Parser, Resolver, fixturesIterator } from "typeorm-fixtures-cli/dist"
import { ConnectionOptions } from "typeorm/connection/ConnectionOptions"

import { configurationTest } from "../config/configuration.test"
import { getRootModuleImports } from "./utils"

export class TestingHelper {
module: TestingModule
app: INestApplication
app: NestFastifyApplication

async initializeModuleAndApp(
testName: string,
importedModules: Array<Type<unknown> | DynamicModule | Promise<DynamicModule> | ForwardReference>,
providers: Provider[] = []
) {
async initializeModuleAndApp(testName: string, importedModules: ModuleMetadata["imports"], providers: Provider[] = undefined) {
const databaseName = `stator_test_${testName}`
const configuration = configurationTest.bind(this, databaseName)

const connection = await createConnection({ ...configuration().database })
const connectionOptions: ConnectionOptions = { ...configuration().database }
const connection = await createConnection(connectionOptions)
await this.createDatabaseIfNotExist(connection, databaseName)

this.module = await Test.createTestingModule({
imports: [...getRootModuleImports(configuration), ...importedModules],
providers: providers,
}).compile()

this.app = this.module.createNestApplication(new FastifyAdapter())
this.app = this.module.createNestApplication<NestFastifyApplication>(new FastifyAdapter())

await this.app.init()
await this.app.getHttpAdapter().getInstance().ready()
Expand All @@ -56,7 +50,7 @@ export class TestingHelper {

for (const fixture of fixtures) {
const entity = await builder.build(fixture)
await getRepository(entity.constructor.name).save(entity)
await connection.getRepository(entity.constructor.name).save(entity)
}
}

Expand All @@ -81,5 +75,6 @@ PERFORM dblink_exec('', 'CREATE DATABASE ${databaseName}');
EXCEPTION WHEN duplicate_database THEN RAISE NOTICE '%, skipping', SQLERRM USING ERRCODE = SQLSTATE;
END
$$;`)
await connection.close()
}
}
19 changes: 8 additions & 11 deletions apps/api/src/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,14 @@ import winston from "winston"
import { getOrmConfigFn } from "../config/configuration"
import { environment } from "../environments/environment"

export const getWinstonConsoleFormat = () => {
if (environment.production) {
return winston.format.json()
}

return winston.format.combine(
winston.format.timestamp(),
winston.format.ms(),
nestWinstonModuleUtilities.format.nestLike("MyApp", { prettyPrint: true })
)
}
export const getWinstonConsoleFormat = () =>
environment.production
? winston.format.json()
: winston.format.combine(
winston.format.timestamp(),
winston.format.ms(),
nestWinstonModuleUtilities.format.nestLike("MyApp", { prettyPrint: true })
)

export const getRootModuleImports = (configuration: ConfigFactory) => [
ConfigModule.forRoot({ isGlobal: true, load: [configuration] }),
Expand Down
2 changes: 1 addition & 1 deletion apps/api/tsconfig.app.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
"emitDecoratorMetadata": true,
"target": "es2015"
},
"exclude": ["**/*.spec.ts"],
"exclude": ["**/*.spec.ts", "**/*.test.ts"],
"include": ["**/*.ts", "**/*.html"]
}
2 changes: 1 addition & 1 deletion apps/api/tsconfig.spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
"module": "commonjs",
"types": ["jest", "node"]
},
"include": ["**/*.spec.ts", "**/*.d.ts"]
"include": ["**/*.spec.ts", "**/*.test.ts", "**/*.d.ts"]
}
8 changes: 0 additions & 8 deletions apps/api/webpack.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
const path = require("path")
const webpack = require("webpack")
const ts = require("typescript")
const HookShellScriptPlugin = require("hook-shell-script-webpack-plugin")
const ExtraWatchWebpackPlugin = require("extra-watch-webpack-plugin")

/**
* Extend the default Webpack configuration from nx / ng.
Expand All @@ -18,12 +16,6 @@ module.exports = config => {
new webpack.ProvidePlugin({
openapi: "@nestjs/swagger",
}),
new ExtraWatchWebpackPlugin({
dirs: ["libs/models/src"],
}),
new HookShellScriptPlugin({
watchRun: ["node ./tools/generators/generate-entity-index-file.js"],
}),
]

return config
Expand Down
20 changes: 20 additions & 0 deletions apps/cli/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"extends": ["../../.eslintrc.json"],
"ignorePatterns": ["!**/*"],
"overrides": [
{
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
"rules": {
"no-irregular-whitespace": "off"
}
},
{
"files": ["*.ts", "*.tsx"],
"rules": {}
},
{
"files": ["*.js", "*.jsx"],
"rules": {}
}
]
}
15 changes: 15 additions & 0 deletions apps/cli/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module.exports = {
displayName: "cli",
preset: "../../jest.preset.js",
globals: {
"ts-jest": {
tsconfig: "<rootDir>/tsconfig.spec.json",
},
},
testEnvironment: "node",
transform: {
"^.+\\.[tj]s$": "ts-jest",
},
moduleFileExtensions: ["ts", "js", "html"],
coverageDirectory: "../../coverage/apps/cli",
}
Loading

0 comments on commit 8146195

Please sign in to comment.