From ce0ca5988ee5ecf21f91ffdad22e66acbd678194 Mon Sep 17 00:00:00 2001 From: Starcea Date: Sat, 10 Aug 2024 17:08:53 +0900 Subject: [PATCH] test: write test codes with gh workflow --- .github/workflows/test.yml | 21 +++++++++++++++++++++ .gitignore | 3 --- package.json | 3 ++- tests/School.test.ts | 14 ++++++++++++++ tests/Timetable.test.ts | 15 +++++++++++++++ tests/index.ts | 3 +++ tsconfig.json | 2 +- 7 files changed, 56 insertions(+), 5 deletions(-) create mode 100644 .github/workflows/test.yml create mode 100644 tests/School.test.ts create mode 100644 tests/Timetable.test.ts create mode 100644 tests/index.ts diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..6664d30 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,21 @@ +name: CI + +on: [push, pull_request, workflow_dispatch] + +jobs: + test: + runs-on: ubuntu-latest + steps: + - name: Checkout branch + uses: actions/checkout@v4 + - name: Setup pnpm + uses: pnpm/action-setup@v4 + - name: Setup node.js 20 + uses: actions/setup-node@v4 + with: + node-version: 20 + cache: "pnpm" + - name: Install Dependencies + run: pnpm i --frozen-lockfile + - name: Run tests + run: pnpm test diff --git a/.gitignore b/.gitignore index 79939a7..f06235c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,2 @@ node_modules dist - -# PIIs included -tests diff --git a/package.json b/package.json index fc11292..643f80b 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,8 @@ "build": "rimraf dist && tsc", "lint": "biome check", "release": "semantic-release", - "prepack": "pnpm build" + "prepack": "pnpm build", + "test": "node -r ts-node/register --test tests/*.test.ts" }, "keywords": ["comcigan", "parser", "typescript", "school", "korean"], "author": "Starcea ", diff --git a/tests/School.test.ts b/tests/School.test.ts new file mode 100644 index 0000000..17a780c --- /dev/null +++ b/tests/School.test.ts @@ -0,0 +1,14 @@ +import assert from 'node:assert' +import test from 'node:test' +import { comcigan } from '.' +import { School } from '../src' + +test('Search schools by name', async () => { + const schools = await comcigan.searchSchools('중학교') + assert(schools.length > 0) +}) + +test('Get school by name', async () => { + const school = await School.fromName('중학교') + assert(school) +}) diff --git a/tests/Timetable.test.ts b/tests/Timetable.test.ts new file mode 100644 index 0000000..669a04a --- /dev/null +++ b/tests/Timetable.test.ts @@ -0,0 +1,15 @@ +import assert from 'node:assert' +import test from 'node:test' +import { comcigan } from '.' + +test('Get timetable by code', async () => { + const schools = await comcigan.searchSchools('중학교') + const timetable = await comcigan.getTimetable(schools[0].code) + assert(timetable) +}) + +test('Get timetable by school', async () => { + const schools = await comcigan.searchSchools('중학교') + const timetable = await schools[0].getTimetable() + assert(timetable) +}) diff --git a/tests/index.ts b/tests/index.ts new file mode 100644 index 0000000..8c47466 --- /dev/null +++ b/tests/index.ts @@ -0,0 +1,3 @@ +import Comcigan from '../src' + +export const comcigan = new Comcigan() diff --git a/tsconfig.json b/tsconfig.json index 099fcfe..2d18ad1 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -100,6 +100,6 @@ // "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */ "skipLibCheck": true /* Skip type checking all .d.ts files. */ }, - "include": ["src"], + "include": ["src", "tests"], "exclude": ["node_modules", "dist"] }