Skip to content

Commit

Permalink
chore: setup test env and add some basic test to implement
Browse files Browse the repository at this point in the history
  • Loading branch information
wa0x6e committed Jul 27, 2023
1 parent 0cc07e6 commit 33f17b1
Show file tree
Hide file tree
Showing 7 changed files with 2,231 additions and 28 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/build-test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Build and run tests
on: [push]
jobs:
build-test:
runs-on: ubuntu-20.04
env:
DATABASE_URL: 'mysql://root:[email protected]:3306/hub_test'
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: '16'
cache: 'yarn'
- name: Set up MySQL
run: |
sudo /etc/init.d/mysql start
mysql -e 'CREATE DATABASE hub_test;' -uroot -proot
mysql -uroot -proot hub_test < src/helpers/schema.sql
mysql -uroot -proot -e "ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'root';"
mysql -uroot -proot -e "FLUSH PRIVILEGES;"
- run: yarn
- run: yarn build
- run: yarn test
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
22 changes: 22 additions & 0 deletions jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* For a detailed explanation regarding each configuration property and type check, visit:
* https://jestjs.io/docs/configuration
*/

export default {
clearMocks: true,
collectCoverage: true,
collectCoverageFrom: ['./src/**'],
coverageDirectory: 'coverage',
coverageProvider: 'v8',

// An array of regexp pattern strings used to skip coverage collection
coveragePathIgnorePatterns: ['/node_modules/', '<rootDir>/dist/', '<rootDir>/test/fixtures/'],

preset: 'ts-jest',
testEnvironment: 'jest-environment-node-single-context',
setupFiles: ['dotenv/config'],
moduleFileExtensions: ['js', 'ts'],
testPathIgnorePatterns: ['dist/'],
verbose: true
};
15 changes: 13 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@
"lint:nofix": "eslint . --ext .ts",
"typecheck": "tsc --noEmit",
"dev": "nodemon src/index.ts",
"start": "ts-node src/index.ts"
"start": "ts-node src/index.ts",
"start:test": "dotenv -e test/.env.test yarn dev",
"test": "PORT=3030 start-server-and-test 'yarn start:test' 3030 'dotenv -e test/.env.test jest --runInBand'",
"test:unit": "dotenv -e test/.env.test jest test/unit/",
"test:e2e": "PORT=3030 start-server-and-test 'yarn start:test' 3030 'dotenv -e test/.env.test jest --runInBand --collectCoverage=false test/e2e/'"
},
"eslintConfig": {
"extends": "@snapshot-labs"
Expand Down Expand Up @@ -45,9 +49,16 @@
"devDependencies": {
"@snapshot-labs/eslint-config": "^0.1.0-beta.7",
"@snapshot-labs/prettier-config": "^0.1.0-beta.7",
"@types/jest": "^29.5.3",
"@types/node": "^14.0.13",
"dotenv-cli": "^7.2.1",
"eslint": "^8.28.0",
"jest": "^29.6.1",
"jest-environment-node-single-context": "^29.1.0",
"nodemon": "^2.0.19",
"prettier": "^2.8.0"
"prettier": "^2.8.0",
"start-server-and-test": "^2.0.0",
"supertest": "^6.3.3",
"ts-jest": "^29.1.1"
}
}
1 change: 1 addition & 0 deletions test/.env.test
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DATABASE_URL=mysql://root:[email protected]:3306/hub_test
3 changes: 3 additions & 0 deletions test/e2e/graphql.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
describe('GET /graphql', () => {
it.todo('exposes a graphql endpoint');
});
9 changes: 9 additions & 0 deletions test/e2e/space.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
describe('GET /api/space/:key', () => {
describe('when the space exists', () => {
it.todo('returns a space object');
});

describe('when the space does not exist', () => {
it.todo('returns a 404 error');
});
});
Loading

0 comments on commit 33f17b1

Please sign in to comment.