diff --git a/packages/test-utils/CHANGELOG.md b/packages/test-utils/CHANGELOG.md new file mode 100644 index 00000000..e69de29b diff --git a/packages/test-utils/README.md b/packages/test-utils/README.md new file mode 100644 index 00000000..e1bd416b --- /dev/null +++ b/packages/test-utils/README.md @@ -0,0 +1,80 @@ +
+ nestjs-logo +

Tresdoce NestJs Toolkit
Test-Utils

+
+ +
+ Node.js + Npm + NestJs
+ GitHub license + GitHub package.json version +
+
+
+ +Este módulo está pensada para ser utilizada en [NestJs Starter](https://github.com/rudemex/nestjs-starter), o cualquier +proyecto que utilice una configuración centralizada, siguiendo la misma arquitectura del starter. + +## Glosario + +- [🥳 Demo](https://rudemex-nestjs-starter.herokuapp.com/docs) +- [📝 Requerimientos básicos](#basic-requirements) +- [🛠️ Instalar dependencia](#install-dependencies) +- [⚙️ Configuración](#configurations) +- [👨‍💻 Uso](#use) +- [📄 Changelog](./CHANGELOG.md) +- [📜 License MIT](./license.md) + +--- + + + +## 📝 Requerimientos básicos + +- [NestJs Starter](https://github.com/rudemex/nestjs-starter) +- Node.js v14.17.0 or higher ([Download](https://nodejs.org/es/download/)) +- YARN v1.22.17 or higher +- NPM v6.14.13 or higher +- NestJS v8.2.6 or higher ([Documentación](https://nestjs.com/)) + + + +## 🛠️ Instalar dependencia + +``` +npm install -S @tresdoce-nestjs-toolkit/test-utils +``` + +``` +yarn add @tresdoce-nestjs-toolkit/test-utils +``` + + + +## ⚙️ Configuración + +```typescript + +``` + + + +## 👨‍💻 Uso + +```typescript + +``` + +## 📄 Changelog + +Todos los cambios notables de este paquete se documentarán en el archivo [Changelog](./CHANGELOG.md). + +--- + +
+ + Mex +
+

Made with ❤

+
diff --git a/packages/test-utils/jest.config.js b/packages/test-utils/jest.config.js new file mode 100644 index 00000000..39c8b313 --- /dev/null +++ b/packages/test-utils/jest.config.js @@ -0,0 +1,6 @@ +const config = require('@tresdoce-nestjs-toolkit/config/jest.config'); + +module.exports = { + ...config, + rootDir: __dirname, +}; diff --git a/packages/test-utils/license.md b/packages/test-utils/license.md new file mode 100644 index 00000000..9f7051f1 --- /dev/null +++ b/packages/test-utils/license.md @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2022 - present Tresdoce & Maximiliano "Mex" Delgado + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NON INFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/packages/test-utils/nest-cli.json b/packages/test-utils/nest-cli.json new file mode 100644 index 00000000..56167b36 --- /dev/null +++ b/packages/test-utils/nest-cli.json @@ -0,0 +1,4 @@ +{ + "collection": "@nestjs/schematics", + "sourceRoot": "src" +} diff --git a/packages/test-utils/package.json b/packages/test-utils/package.json new file mode 100644 index 00000000..cf1b825c --- /dev/null +++ b/packages/test-utils/package.json @@ -0,0 +1,83 @@ +{ + "name": "@tresdoce-nestjs-toolkit/test-utils", + "version": "0.0.0", + "description": "Tresdoce NestJS Toolkit - test-utils", + "author": { + "name": "Maximiliano \"Mex\" Delgado", + "email": "mdelgado@tresdoce.com.ar", + "url": "https://rudemex.github.io/" + }, + "directories": { + "lib": "lib", + "test": "__tests__" + }, + "keywords": [ + "nestjs", + "test-utils" + ], + "repository": { + "type": "git", + "url": "git+https://github.com/tresdoce/tresdoce-nestjs-toolkit.git" + }, + "bugs": { + "url": "https://github.com/tresdoce/tresdoce-nestjs-toolkit/issues" + }, + "homepage": "https://github.com/tresdoce/tresdoce-nestjs-toolkit#readme", + "main": "src/index.ts", + "license": "MIT", + "scripts": { + "prebuild": "shx rm -rf pkg", + "build": "pika build --out ../../dist/test-utils", + "test": "jest --runInBand --detectOpenHandles --coverage" + }, + "publishConfig": { + "access": "public", + "directory": "../../dist/test-utils" + }, + "peerDependencies": { + "@nestjs/common": "^8.2.0", + "@nestjs/core": "^8.2.0", + "@nestjs/platform-express": "^8.2.0", + "reflect-metadata": "^0.1.13", + "rxjs": "^7.5.5" + }, + "devDependencies": { + "@tresdoce-nestjs-toolkit/config": "^0.0.0", + "@types/tresdoce-nestjs-toolkit": "^0.0.0" + }, + "prettier": { + "semi": true, + "tabWidth": 2, + "singleQuote": true, + "printWidth": 100, + "trailingComma": "all" + }, + "@pika/pack": { + "pipeline": [ + [ + "@pika/plugin-ts-standard-pkg", + { + "exclude": [ + "**/__test__/*" + ] + } + ], + [ + "@pika/plugin-build-node", + { + "exclude": [ + "**/__test__/*" + ] + } + ], + [ + "@pika/plugin-build-types", + { + "exclude": [ + "**/__test__/*" + ] + } + ] + ] + } +} diff --git a/packages/test-utils/src/__test__/greeting.module.spec.ts b/packages/test-utils/src/__test__/greeting.module.spec.ts new file mode 100644 index 00000000..ea8cbaca --- /dev/null +++ b/packages/test-utils/src/__test__/greeting.module.spec.ts @@ -0,0 +1,20 @@ +import { Test, TestingModule } from '@nestjs/testing'; +import { INestApplication } from '@nestjs/common'; +import { GreetingModule } from '../greeting/greeting.module'; + +describe('GreetingModule', () => { + let app: INestApplication; + + beforeEach(async () => { + const moduleFixture: TestingModule = await Test.createTestingModule({ + imports: [GreetingModule], + }).compile(); + + app = moduleFixture.createNestApplication(); + await app.init(); + }); + + it('should be defined', () => { + expect(app).toBeDefined(); + }); +}); diff --git a/packages/test-utils/src/__test__/greeting.service.spec.ts b/packages/test-utils/src/__test__/greeting.service.spec.ts new file mode 100644 index 00000000..3fd05829 --- /dev/null +++ b/packages/test-utils/src/__test__/greeting.service.spec.ts @@ -0,0 +1,21 @@ +import { Test, TestingModule } from '@nestjs/testing'; +import { GreetingService } from '../greeting/services/greeting.service'; + +describe('GreetingService', () => { + let service: GreetingService; + + beforeEach(async () => { + const module: TestingModule = await Test.createTestingModule({ + providers: [GreetingService], + }).compile(); + + service = module.get(GreetingService); + }); + + it('should be defined', () => { + expect(service).toBeDefined(); + }); + it('should be return message when call the getHello function', () => { + expect(service.getHello()).toBe('¡Hello from the new package test-utils!'); + }); +}); diff --git a/packages/test-utils/src/greeting/greeting.module.ts b/packages/test-utils/src/greeting/greeting.module.ts new file mode 100644 index 00000000..2357149c --- /dev/null +++ b/packages/test-utils/src/greeting/greeting.module.ts @@ -0,0 +1,9 @@ +import { Global, Module } from '@nestjs/common'; +import { GreetingService } from './services/greeting.service'; + +@Global() +@Module({ + providers: [GreetingService], + exports: [GreetingService], +}) +export class GreetingModule {} diff --git a/packages/test-utils/src/greeting/services/greeting.service.ts b/packages/test-utils/src/greeting/services/greeting.service.ts new file mode 100644 index 00000000..79c0303d --- /dev/null +++ b/packages/test-utils/src/greeting/services/greeting.service.ts @@ -0,0 +1,8 @@ +import { Injectable } from '@nestjs/common'; + +@Injectable() +export class GreetingService { + getHello(): string { + return '¡Hello from the new package test-utils!'; + } +} diff --git a/packages/test-utils/src/index.ts b/packages/test-utils/src/index.ts new file mode 100644 index 00000000..397304d3 --- /dev/null +++ b/packages/test-utils/src/index.ts @@ -0,0 +1,5 @@ +// export public api from here +// for example: +// export * from './decorators'; +export * from './greeting/greeting.module'; +export * from './greeting/services/greeting.service'; diff --git a/packages/test-utils/tsconfig.build.json b/packages/test-utils/tsconfig.build.json new file mode 100644 index 00000000..12e3794d --- /dev/null +++ b/packages/test-utils/tsconfig.build.json @@ -0,0 +1,15 @@ +{ + "extends": "./tsconfig", + "exclude": [ + "node_modules", + "dist", + "test", + "__test__", + "**/__test__/**/*", + "**/*spec.ts", + "**/*it.ts", + "**/*test.ts", + "**/*e2e.ts", + "**/*e2e-spec.ts" + ] +} diff --git a/packages/test-utils/tsconfig.json b/packages/test-utils/tsconfig.json new file mode 100644 index 00000000..32b40009 --- /dev/null +++ b/packages/test-utils/tsconfig.json @@ -0,0 +1,21 @@ +{ + "extends": "@tresdoce-nestjs-toolkit/config", + "compilerOptions": { + "rootDir": "./src", + "types": ["tresdoce-nestjs-toolkit"] + }, + "include": ["src/**/*"], + "exclude": [ + "node_modules", + "dist", + "test", + "__test__", + "**/__test__/**/*", + "**/*spec.ts", + "**/*it.ts", + "**/*test.ts", + "**/*e2e.ts", + "**/*e2e-spec.ts", + "coverage" + ] +} diff --git a/plops/package-template.js b/plops/package-template.js index 2e19d03d..4c8a3ca6 100644 --- a/plops/package-template.js +++ b/plops/package-template.js @@ -10,72 +10,72 @@ module.exports = { actions: () => { let actions = []; actions = actions.concat( - { - type: 'add', - path: 'packages/{{kebabCase packageName}}/README.md', - templateFile: 'plops-templates/packages/basic/README.md.hbs', - }, - { - type: 'add', - path: 'packages/{{kebabCase packageName}}/tsconfig.json', - templateFile: 'plops-templates/packages/basic/tsconfig.json.hbs', - }, - { - type: 'add', - path: 'packages/{{kebabCase packageName}}/tsconfig.build.json', - templateFile: 'plops-templates/packages/basic/tsconfig.build.json.hbs', - }, - { - type: 'add', - path: 'packages/{{kebabCase packageName}}/package.json', - templateFile: 'plops-templates/packages/basic/package.json.hbs', - }, - { - type: 'add', - path: 'packages/{{kebabCase packageName}}/nest-cli.json', - templateFile: 'plops-templates/packages/basic/nest-cli.json.hbs', - }, - { - type: 'add', - path: 'packages/{{kebabCase packageName}}/jest.config.js', - templateFile: 'plops-templates/packages/basic/jest.config.js.hbs', - }, - { - type: 'add', - path: 'packages/{{kebabCase packageName}}/CHANGELOG.md', - templateFile: 'plops-templates/packages/basic/CHANGELOG.md.hbs', - }, - { - type: 'add', - path: 'packages/{{kebabCase packageName}}/license.md', - templateFile: 'plops-templates/packages/basic/license.md.hbs', - }, - { - type: 'add', - path: 'packages/{{kebabCase packageName}}/src/index.ts', - templateFile: 'plops-templates/packages/basic/src/index.ts.hbs', - }, - { - type: 'add', - path: 'packages/{{kebabCase packageName}}/src/typeorm/typeorm.module.ts', - templateFile: 'plops-templates/packages/basic/src/typeorm/typeorm.module.ts.hbs', - }, - { - type: 'add', - path: 'packages/{{kebabCase packageName}}/src/typeorm/services/typeorm.service.ts', - templateFile: - 'plops-templates/packages/basic/src/typeorm/services/typeorm.service.ts.hbs', - }, - { - type: 'add', - path: 'packages/{{kebabCase packageName}}/src/__test__/typeorm.module.spec.ts', - templateFile: 'plops-templates/packages/basic/src/__test__/typeorm.module.spec.ts.hbs', - }, - { - type: 'add', - path: 'packages/{{kebabCase packageName}}/src/__test__/typeorm.service.spec.ts', - templateFile: 'plops-templates/packages/basic/src/__test__/typeorm.service.spec.ts.hbs', - }, + { + type: 'add', + path: 'packages/{{kebabCase packageName}}/README.md', + templateFile: 'plops-templates/packages/basic/README.md.hbs', + }, + { + type: 'add', + path: 'packages/{{kebabCase packageName}}/tsconfig.json', + templateFile: 'plops-templates/packages/basic/tsconfig.json.hbs', + }, + { + type: 'add', + path: 'packages/{{kebabCase packageName}}/tsconfig.build.json', + templateFile: 'plops-templates/packages/basic/tsconfig.build.json.hbs', + }, + { + type: 'add', + path: 'packages/{{kebabCase packageName}}/package.json', + templateFile: 'plops-templates/packages/basic/package.json.hbs', + }, + { + type: 'add', + path: 'packages/{{kebabCase packageName}}/nest-cli.json', + templateFile: 'plops-templates/packages/basic/nest-cli.json.hbs', + }, + { + type: 'add', + path: 'packages/{{kebabCase packageName}}/jest.config.js', + templateFile: 'plops-templates/packages/basic/jest.config.js.hbs', + }, + { + type: 'add', + path: 'packages/{{kebabCase packageName}}/CHANGELOG.md', + templateFile: 'plops-templates/packages/basic/CHANGELOG.md.hbs', + }, + { + type: 'add', + path: 'packages/{{kebabCase packageName}}/license.md', + templateFile: 'plops-templates/packages/basic/license.md.hbs', + }, + { + type: 'add', + path: 'packages/{{kebabCase packageName}}/src/index.ts', + templateFile: 'plops-templates/packages/basic/src/index.ts.hbs', + }, + { + type: 'add', + path: 'packages/{{kebabCase packageName}}/src/greeting/greeting.module.ts', + templateFile: 'plops-templates/packages/basic/src/greeting/greeting.module.ts.hbs', + }, + { + type: 'add', + path: 'packages/{{kebabCase packageName}}/src/greeting/services/greeting.service.ts', + templateFile: + 'plops-templates/packages/basic/src/greeting/services/greeting.service.ts.hbs', + }, + { + type: 'add', + path: 'packages/{{kebabCase packageName}}/src/__test__/greeting.module.spec.ts', + templateFile: 'plops-templates/packages/basic/src/__test__/greeting.module.spec.ts.hbs', + }, + { + type: 'add', + path: 'packages/{{kebabCase packageName}}/src/__test__/greeting.service.spec.ts', + templateFile: 'plops-templates/packages/basic/src/__test__/greeting.service.spec.ts.hbs', + }, ); return actions; },