Skip to content

Commit

Permalink
test: add unittest (#4)
Browse files Browse the repository at this point in the history
* test: add unittest
  • Loading branch information
LichKing-2234 authored Sep 27, 2023
1 parent bb2a1f0 commit d45b4c7
Show file tree
Hide file tree
Showing 15 changed files with 1,126 additions and 36 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Unit test

on:
pull_request:

jobs:
test:
runs-on: ubuntu-latest
permissions:
contents: read
packages: read
steps:
- uses: actions/checkout@v3
# Setup .npmrc file to publish to GitHub Packages
- uses: actions/setup-node@v3
with:
node-version: "16.x"
registry-url: "https://npm.pkg.github.com"
# Defaults to the user or organization that owns the workflow file
scope: "@agoraio-extensions"

- name: Run unit test
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
npm install
npm run test
2 changes: 1 addition & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ module.exports = {
coverageDirectory: 'coverage',
preset: 'ts-jest',
testEnvironment: 'node',
testRegex: '/__tests__/.*\\.(test|spec)\\.[jt]sx?$',
testRegex: 'src/__tests__/.*\\.(test|spec)\\.[jt]sx?$',
};
24 changes: 6 additions & 18 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
"author": "",
"license": "ISC",
"dependencies": {
"@agoraio-extensions/cxx-parser": ">=0.1.3",
"@agoraio-extensions/terra-core": ">=0.1.2",
"@agoraio-extensions/cxx-parser": "latest",
"@agoraio-extensions/terra-core": "latest",
"mustache": "^4.2.0"
},
"devDependencies": {
Expand Down
18 changes: 18 additions & 0 deletions src/__tests__/parsers/add_node_parser.mock.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
export const parseMock = jest.fn();
// export const generateCustomNodesMock = jest.fn();
jest.mock('@agoraio-extensions/cxx-parser', () => {
const originalModule = jest.requireActual('@agoraio-extensions/cxx-parser');
return {
__esModule: true,
...originalModule,
CXXParser: parseMock,
};
});

import * as Tester from '../../parsers/add_node_parser';

export const generateCustomNodesMock = jest.spyOn(
Tester,
'generateCustomNodes'
);
export const AddNodeParser = Tester.AddNodeParser;
Loading

0 comments on commit d45b4c7

Please sign in to comment.