Skip to content

Commit

Permalink
feat(test-utils): create pkg to test utils
Browse files Browse the repository at this point in the history
  • Loading branch information
rudemex committed Apr 27, 2022
1 parent c3b089f commit 921e533
Show file tree
Hide file tree
Showing 14 changed files with 359 additions and 66 deletions.
Empty file.
80 changes: 80 additions & 0 deletions packages/test-utils/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<div align="center">
<img alt="nestjs-logo" width="250" height="auto" src="https://camo.githubusercontent.com/c704e8013883cc3a04c7657e656fe30be5b188145d759a6aaff441658c5ffae0/68747470733a2f2f6e6573746a732e636f6d2f696d672f6c6f676f5f746578742e737667" />
<h1>Tresdoce NestJs Toolkit<br/>Test-Utils</h1>
</div>

<div align="center">
<img src="https://img.shields.io/static/v1.svg?style=flat&label=Node&message=v14.17.0&labelColor=339933&color=757575&logoColor=FFFFFF&logo=Node.js" alt="Node.js"/>
<img src="https://img.shields.io/static/v1.svg?style=flat&label=Npm&message=v6.14.13&labelColor=CB3837&logoColor=FFFFFF&color=757575&logo=npm" alt="Npm"/>
<img src="https://img.shields.io/static/v1.svg?style=flat&label=NestJs&message=v8.2.6&labelColor=E0234E&logoColor=FFFFFF&color=757575&logo=Nestjs" alt="NestJs"/><br/>
<img alt="GitHub license" src="https://img.shields.io/github/license/tresdoce/tresdoce-nestjs-toolkit?style=flat">
<img alt="GitHub package.json version" src="https://img.shields.io/github/package-json/v/tresdoce/tresdoce-nestjs-toolkit?filename=packages%2Ftest-utils%2Fpackage.json">
<br/>
</div>
<br/>

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)

---

<a name="basic-requirements"></a>

## 📝 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/))

<a name="install-dependencies"></a>

## 🛠️ Instalar dependencia

```
npm install -S @tresdoce-nestjs-toolkit/test-utils
```

```
yarn add @tresdoce-nestjs-toolkit/test-utils
```

<a name="configurations"></a>

## ⚙️ Configuración

```typescript

```

<a name="use"></a>

## 👨‍💻 Uso

```typescript

```

## 📄 Changelog

Todos los cambios notables de este paquete se documentarán en el archivo [Changelog](./CHANGELOG.md).

---

<div align="center">
<a href="mailto:mdelgado@tresdoce.com.ar" target="_blank" alt="Send an email">
<img src="../../.readme-static/logo-mex-red.svg" width="120" alt="Mex" />
</a><br/>
<p>Made with ❤</p>
</div>
6 changes: 6 additions & 0 deletions packages/test-utils/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const config = require('@tresdoce-nestjs-toolkit/config/jest.config');

module.exports = {
...config,
rootDir: __dirname,
};
21 changes: 21 additions & 0 deletions packages/test-utils/license.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2022 - present Tresdoce & Maximiliano "Mex" Delgado <mdelgado@tresdoce.com.ar>

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.
4 changes: 4 additions & 0 deletions packages/test-utils/nest-cli.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"collection": "@nestjs/schematics",
"sourceRoot": "src"
}
83 changes: 83 additions & 0 deletions packages/test-utils/package.json
Original file line number Diff line number Diff line change
@@ -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__/*"
]
}
]
]
}
}
20 changes: 20 additions & 0 deletions packages/test-utils/src/__test__/greeting.module.spec.ts
Original file line number Diff line number Diff line change
@@ -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();
});
});
21 changes: 21 additions & 0 deletions packages/test-utils/src/__test__/greeting.service.spec.ts
Original file line number Diff line number Diff line change
@@ -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>(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!');
});
});
9 changes: 9 additions & 0 deletions packages/test-utils/src/greeting/greeting.module.ts
Original file line number Diff line number Diff line change
@@ -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 {}
8 changes: 8 additions & 0 deletions packages/test-utils/src/greeting/services/greeting.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { Injectable } from '@nestjs/common';

@Injectable()
export class GreetingService {
getHello(): string {
return '¡Hello from the new package test-utils!';
}
}
5 changes: 5 additions & 0 deletions packages/test-utils/src/index.ts
Original file line number Diff line number Diff line change
@@ -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';
15 changes: 15 additions & 0 deletions packages/test-utils/tsconfig.build.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"extends": "./tsconfig",
"exclude": [
"node_modules",
"dist",
"test",
"__test__",
"**/__test__/**/*",
"**/*spec.ts",
"**/*it.ts",
"**/*test.ts",
"**/*e2e.ts",
"**/*e2e-spec.ts"
]
}
21 changes: 21 additions & 0 deletions packages/test-utils/tsconfig.json
Original file line number Diff line number Diff line change
@@ -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"
]
}
Loading

0 comments on commit 921e533

Please sign in to comment.