Skip to content
This repository was archived by the owner on Dec 6, 2021. It is now read-only.

Commit 9034092

Browse files
authored
πŸ‘·β€β™‚οΈ GitHub action tests
2 parents 05fae89 + ccbc48c commit 9034092

18 files changed

+6203
-949
lines changed

β€Ž.env.exampleβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
JWT_SECRET=secret
22
DB_USERNAME=root
33
DB_PASSWORD=root
4-
DB_NAME=node-api-example
4+
DB_NAME=node-api-boilerplate
55
DB_HOSTNAME=localhost
66
DB_PORT=3306
77
DB_DIALECT=mysql
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node
2+
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions
3+
4+
name: Node.js CI
5+
6+
on:
7+
push:
8+
branches: [main]
9+
pull_request:
10+
branches: [main]
11+
12+
jobs:
13+
build:
14+
runs-on: ubuntu-latest
15+
env:
16+
NODE_ENV: test
17+
JWT_SECRET: secret
18+
19+
strategy:
20+
matrix:
21+
node-version: [10.x, 12.x, 14.x]
22+
23+
steps:
24+
- name: Start MySQL
25+
run: sudo service mysql start
26+
- uses: actions/checkout@v2
27+
- name: Make envfile
28+
uses: SpicyPizza/create-envfile@v1
29+
with:
30+
JWT_SECRET: secret
31+
- name: Use Node.js ${{ matrix.node-version }}
32+
uses: actions/setup-node@v1
33+
with:
34+
node-version: ${{ matrix.node-version }}
35+
- run: npm ci
36+
- run: npm test

β€Ž.gitignoreβ€Ž

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,4 +101,7 @@ dist
101101
.dynamodb/
102102

103103
# TernJS port file
104-
.tern-port
104+
.tern-port
105+
106+
# macOS
107+
.DS_Store

β€Žapp.jsβ€Ž

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,17 @@ var express = require("express");
22
var logger = require("morgan");
33
require("dotenv").config();
44

5-
const { handleError } = require("./helpers/ErrorHandler");
5+
const { handleError } = require("./helpers/errorHandler");
66

77
var indexRouter = require("./routes/index");
88
var usersRouter = require("./routes/users");
99
var authRouter = require("./routes/auth");
1010

1111
var app = express();
1212

13-
app.use(logger("dev"));
13+
if (process.env === "development" || process.env === "production") {
14+
app.use(logger("dev"));
15+
}
1416
app.use(express.json());
1517
app.use("/", indexRouter);
1618
app.use("/api/v1/users", usersRouter);

β€Žconfig/config.jsβ€Ž

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,16 @@ module.exports = {
88
host: process.env.DB_HOSTNAME,
99
port: process.env.DB_PORT,
1010
dialect: process.env.DB_DIALECT,
11+
logging: true,
1112
},
1213
test: {
13-
username: process.env.DB_USERNAME,
14-
password: process.env.DB_PASSWORD,
15-
database: process.env.DB_NAME,
16-
host: process.env.DB_HOSTNAME,
17-
port: process.env.DB_PORT,
18-
dialect: process.env.DB_DIALECT,
14+
username: "root",
15+
password: "root",
16+
database: "node-api-boilerplate-test",
17+
host: "127.0.0.1",
18+
port: 3306,
19+
dialect: "mysql",
20+
logging: false,
1921
},
2022
production: {
2123
username: process.env.DB_USERNAME,
@@ -24,5 +26,6 @@ module.exports = {
2426
host: process.env.DB_HOSTNAME,
2527
port: process.env.DB_PORT,
2628
dialect: process.env.DB_DIALECT,
29+
logging: false,
2730
},
2831
};

β€Žjest.config.jsβ€Ž

Lines changed: 194 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,194 @@
1+
/*
2+
* For a detailed explanation regarding each configuration property, visit:
3+
* https://jestjs.io/docs/en/configuration.html
4+
*/
5+
6+
module.exports = {
7+
// All imported modules in your tests should be mocked automatically
8+
// automock: false,
9+
10+
// Stop running tests after `n` failures
11+
// bail: 0,
12+
13+
// The directory where Jest should store its cached dependency information
14+
// cacheDirectory: "C:\\Users\\Jeremy\\AppData\\Local\\Temp\\jest",
15+
16+
// Automatically clear mock calls and instances between every test
17+
clearMocks: true,
18+
19+
// Indicates whether the coverage information should be collected while executing the test
20+
// collectCoverage: false,
21+
22+
// An array of glob patterns indicating a set of files for which coverage information should be collected
23+
// collectCoverageFrom: undefined,
24+
25+
// The directory where Jest should output its coverage files
26+
coverageDirectory: "coverage",
27+
28+
// An array of regexp pattern strings used to skip coverage collection
29+
// coveragePathIgnorePatterns: [
30+
// "\\\\node_modules\\\\"
31+
// ],
32+
33+
// Indicates which provider should be used to instrument code for coverage
34+
coverageProvider: "v8",
35+
36+
// A list of reporter names that Jest uses when writing coverage reports
37+
// coverageReporters: [
38+
// "json",
39+
// "text",
40+
// "lcov",
41+
// "clover"
42+
// ],
43+
44+
// An object that configures minimum threshold enforcement for coverage results
45+
// coverageThreshold: undefined,
46+
47+
// A path to a custom dependency extractor
48+
// dependencyExtractor: undefined,
49+
50+
// Make calling deprecated APIs throw helpful error messages
51+
// errorOnDeprecated: false,
52+
53+
// Force coverage collection from ignored files using an array of glob patterns
54+
// forceCoverageMatch: [],
55+
56+
// A path to a module which exports an async function that is triggered once before all test suites
57+
// globalSetup: undefined,
58+
59+
// A path to a module which exports an async function that is triggered once after all test suites
60+
// globalTeardown: undefined,
61+
62+
// A set of global variables that need to be available in all test environments
63+
// globals: {},
64+
65+
// The maximum amount of workers used to run your tests. Can be specified as % or a number. E.g. maxWorkers: 10% will use 10% of your CPU amount + 1 as the maximum worker number. maxWorkers: 2 will use a maximum of 2 workers.
66+
// maxWorkers: "50%",
67+
68+
// An array of directory names to be searched recursively up from the requiring module's location
69+
// moduleDirectories: [
70+
// "node_modules"
71+
// ],
72+
73+
// An array of file extensions your modules use
74+
// moduleFileExtensions: [
75+
// "js",
76+
// "json",
77+
// "jsx",
78+
// "ts",
79+
// "tsx",
80+
// "node"
81+
// ],
82+
83+
// A map from regular expressions to module names or to arrays of module names that allow to stub out resources with a single module
84+
// moduleNameMapper: {},
85+
86+
// An array of regexp pattern strings, matched against all module paths before considered 'visible' to the module loader
87+
// modulePathIgnorePatterns: [],
88+
89+
// Activates notifications for test results
90+
// notify: false,
91+
92+
// An enum that specifies notification mode. Requires { notify: true }
93+
// notifyMode: "failure-change",
94+
95+
// A preset that is used as a base for Jest's configuration
96+
// preset: undefined,
97+
98+
// Run tests from one or more projects
99+
// projects: undefined,
100+
101+
// Use this configuration option to add custom reporters to Jest
102+
// reporters: undefined,
103+
104+
// Automatically reset mock state between every test
105+
// resetMocks: false,
106+
107+
// Reset the module registry before running each individual test
108+
// resetModules: false,
109+
110+
// A path to a custom resolver
111+
// resolver: undefined,
112+
113+
// Automatically restore mock state between every test
114+
// restoreMocks: false,
115+
116+
// The root directory that Jest should scan for tests and modules within
117+
// rootDir: undefined,
118+
119+
// A list of paths to directories that Jest should use to search for files in
120+
// roots: [
121+
// "<rootDir>"
122+
// ],
123+
124+
// Allows you to use a custom runner instead of Jest's default test runner
125+
// runner: "jest-runner",
126+
127+
// The paths to modules that run some code to configure or set up the testing environment before each test
128+
// setupFiles: [],
129+
130+
// A list of paths to modules that run some code to configure or set up the testing framework before each test
131+
// setupFilesAfterEnv: [],
132+
133+
// The number of seconds after which a test is considered as slow and reported as such in the results.
134+
// slowTestThreshold: 5,
135+
136+
// A list of paths to snapshot serializer modules Jest should use for snapshot testing
137+
// snapshotSerializers: [],
138+
139+
// The test environment that will be used for testing
140+
testEnvironment: "node",
141+
142+
// Options that will be passed to the testEnvironment
143+
// testEnvironmentOptions: {},
144+
145+
// Adds a location field to test results
146+
// testLocationInResults: false,
147+
148+
// The glob patterns Jest uses to detect test files
149+
// testMatch: [
150+
// "**/__tests__/**/*.[jt]s?(x)",
151+
// "**/?(*.)+(spec|test).[tj]s?(x)"
152+
// ],
153+
154+
// An array of regexp pattern strings that are matched against all test paths, matched tests are skipped
155+
// testPathIgnorePatterns: [
156+
// "\\\\node_modules\\\\"
157+
// ],
158+
159+
// The regexp pattern or array of patterns that Jest uses to detect test files
160+
// testRegex: [],
161+
162+
// This option allows the use of a custom results processor
163+
// testResultsProcessor: undefined,
164+
165+
// This option allows use of a custom test runner
166+
// testRunner: "jasmine2",
167+
168+
// This option sets the URL for the jsdom environment. It is reflected in properties such as location.href
169+
// testURL: "http://localhost",
170+
171+
// Setting this value to "fake" allows the use of fake timers for functions such as "setTimeout"
172+
// timers: "real",
173+
174+
// A map from regular expressions to paths to transformers
175+
// transform: undefined,
176+
177+
// An array of regexp pattern strings that are matched against all source file paths, matched files will skip transformation
178+
// transformIgnorePatterns: [
179+
// "\\\\node_modules\\\\",
180+
// "\\.pnp\\.[^\\\\]+$"
181+
// ],
182+
183+
// An array of regexp pattern strings that are matched against all modules before the module loader will automatically return a mock for them
184+
// unmockedModulePathPatterns: undefined,
185+
186+
// Indicates whether each individual test should be reported during the run
187+
// verbose: undefined,
188+
189+
// An array of regexp patterns that are matched against all source file paths before re-running tests in watch mode
190+
// watchPathIgnorePatterns: [],
191+
192+
// Whether to use watchman for file crawling
193+
// watchman: true,
194+
};

β€Žmiddlewares/verifyToken.jsβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const jwt = require("jsonwebtoken");
22
const HttpStatus = require("http-status-codes");
3-
const { ErrorHandler } = require("../helpers/ErrorHandler");
3+
const { ErrorHandler } = require("../helpers/errorHandler");
44
require("dotenv").config();
55

66
async function verifyToken(req, res, next) {

β€Žmigrations/20201205122709-create-user.jsβ€Ž

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"use strict";
22
module.exports = {
33
up: async (queryInterface, Sequelize) => {
4-
await queryInterface.createTable("Users", {
4+
await queryInterface.createTable("users", {
55
id: {
66
allowNull: false,
77
autoIncrement: true,
@@ -35,6 +35,6 @@ module.exports = {
3535
});
3636
},
3737
down: async (queryInterface, Sequelize) => {
38-
await queryInterface.dropTable("Users");
38+
await queryInterface.dropTable("users");
3939
},
4040
};

β€Žmigrations/20201205232447-create-jwt-token.jsβ€Ž

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"use strict";
22
module.exports = {
33
up: async (queryInterface, Sequelize) => {
4-
await queryInterface.createTable("JwtTokens", {
4+
await queryInterface.createTable("jwt_tokens", {
55
id: {
66
allowNull: false,
77
autoIncrement: true,
@@ -27,6 +27,6 @@ module.exports = {
2727
});
2828
},
2929
down: async (queryInterface, Sequelize) => {
30-
await queryInterface.dropTable("JwtTokens");
30+
await queryInterface.dropTable("jwt_tokens");
3131
},
3232
};

β€Žmigrations/20201205232653-create-jwt-refresh-token.jsβ€Ž

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"use strict";
22
module.exports = {
33
up: async (queryInterface, Sequelize) => {
4-
await queryInterface.createTable("JwtRefreshTokens", {
4+
await queryInterface.createTable("jwt_refresh_tokens", {
55
id: {
66
allowNull: false,
77
autoIncrement: true,
@@ -27,6 +27,6 @@ module.exports = {
2727
});
2828
},
2929
down: async (queryInterface, Sequelize) => {
30-
await queryInterface.dropTable("JwtRefreshTokens");
30+
await queryInterface.dropTable("jwt_refresh_tokens");
3131
},
3232
};

0 commit comments

Comments
Β (0)