Skip to content

Commit

Permalink
test: adds unit tests, adds pre-push hook, adds test step into CI
Browse files Browse the repository at this point in the history
  • Loading branch information
Davide Gaggero committed Nov 4, 2021
1 parent fc07bc0 commit 0912604
Show file tree
Hide file tree
Showing 8 changed files with 2,093 additions and 96 deletions.
20 changes: 17 additions & 3 deletions .github/workflows/cy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,14 @@ on:
pull_request:
branches:
- '*'

jobs:
build:
runs-on: ubuntu-latest
environment:
name: build
strategy:
matrix:
node-version: [12.x, 14.x]
node-version: [12.x, 14.x, 16.x]
steps:
- uses: actions/checkout@v2
- name: Use Node Version ${{ matrix.node-version }}
Expand Down Expand Up @@ -48,9 +47,24 @@ jobs:
restore-keys: |
${{ runner.os }}-${{ matrix.node-version }}-nodemodules-
- uses: actions/cache@v2
name: Cache Jest cache
id: cache-jest-cache
with:
path: .jest-cache
key: ${{ runner.os }}-${{ matrix.node-version }}-jest

- name: Install Dependencies
run: yarn --frozen-lockfile
if: steps.cache-yarn-cache.outputs.cache-hit != 'true' || steps.cache-node-modules.outputs.cache-hit != 'true'
if: steps.cache-yarn-cache.outputs.cache-hit != 'true' || steps.cache-node-modules.outputs.cache-hit != 'true'

- name: Unit tests
run: yarn test --all --cacheDirectory .jest-cache --coverage --watchAll false
- uses: vebr/jest-lcov-reporter@v0.2.0
# Print comment only on 1 build and PR
if: matrix.node-version == '12.x' && github.event_name == 'pull_request'
with:
github-token: ${{ secrets.GITHUB_TOKEN }}

release:
runs-on: ubuntu-latest
Expand Down
1 change: 1 addition & 0 deletions .husky/pre-push
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
yarn test --all --watchAll false
10 changes: 10 additions & 0 deletions config/jest/fileTransform.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const path = require('path');

// This is a custom Jest transformer turning file imports into filenames.
// http://facebook.github.io/jest/docs/tutorial-webpack.html

module.exports = {
process(src, filename) {
return `module.exports = ${JSON.stringify(path.basename(filename))};`;
},
}
5 changes: 4 additions & 1 deletion example/integration.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import Bee from '../src/index'
import { IBeeConfig, IMergeContent, IMergeTag, ISpecialLink, LoadWorkspaceOptions, StageDisplayOptions, StageModeOptions } from '../src/types/bee';
import {
IBeeConfig, IMergeContent, IMergeTag, ISpecialLink,
LoadWorkspaceOptions, StageDisplayOptions, StageModeOptions
} from '../src/types/bee';
declare let saveAs: any;

const BEE_TEMPLATE_URL = 'https://rsrc.getbee.io/api/templates/m-bee'
Expand Down
17 changes: 17 additions & 0 deletions jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@

import type { Config } from '@jest/types'
import { defaults } from 'jest-config'

export default async (): Promise<Config.InitialOptions> => {
return {
verbose: true,
preset: 'ts-jest',
moduleFileExtensions: [...defaults.moduleFileExtensions, 'ts', 'tsx'],
transform: {
"^.+\\.(js|css|png|jpg|jpeg|gif|svg)$": "<rootDir>/config/jest/fileTransform.js"
},
transformIgnorePatterns: [
"node_modules/*"
]
}
}
8 changes: 7 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,16 @@
"husky": {
"hooks": {
"pre-commit": "lint-staged",
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS"
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS",
"pre-push": "yarn test --all --watchAll false"
}
},
"lint-staged": {
"*.ts": "eslint"
},
"scripts": {
"start": "npx webpack serve",
"test": "jest",
"clean": "rimraf dist",
"build": "yarn lint && yarn clean && rollup -c && tsc",
"prepare": "husky install",
Expand Down Expand Up @@ -48,20 +50,24 @@
"@rollup/plugin-json": "^4.1.0",
"@rollup/plugin-node-resolve": "^13.0.4",
"@rollup/plugin-url": "^6.1.0",
"@types/jest": "^27.0.2",
"@typescript-eslint/eslint-plugin": "^4.29.2",
"@typescript-eslint/parser": "^4.29.2",
"dotenv": "^10.0.0",
"eslint": "^7.32.0",
"eslint-plugin-import": "^2.24.1",
"eslint-plugin-jsx-a11y": "^6.4.1",
"husky": "7.0.1",
"jest": "^27.3.1",
"lint-staged": "11.1.2",
"rimraf": "^3.0.0",
"rollup": "^2.56.2",
"rollup-plugin-peer-deps-external": "^2.2.4",
"rollup-plugin-typescript2": "^0.30.0",
"standard-version": "^9.3.1",
"ts-jest": "^27.0.7",
"ts-loader": "^8.2.0",
"ts-node": "^10.4.0",
"typescript": "^4.3.5",
"webpack": "^5.51.1",
"webpack-cli": "^4.8.0",
Expand Down
33 changes: 33 additions & 0 deletions src/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import BeePlugin from './index'


describe("BeePlugin", () => {
const beeInstance = new BeePlugin()
test('should test interface', () => {
expect(typeof beeInstance.preview).toBe("function")
expect(typeof beeInstance.reload).toBe("function")
expect(typeof beeInstance.save).toBe("function")
expect(typeof beeInstance.saveAsTemplate).toBe("fusnction")
expect(typeof beeInstance.send).toBe("function")
expect(typeof beeInstance.showComment).toBe("function")
expect(typeof beeInstance.start).toBe("function")
expect(typeof beeInstance.join).toBe("function")
expect(typeof beeInstance.toggleComments).toBe("function")
expect(typeof beeInstance.toggleMergeTagsPreview).toBe("function")
expect(typeof beeInstance.togglePreview).toBe("function")
expect(typeof beeInstance.toggleStructure).toBe("function")
expect(typeof beeInstance.getToken).toBe("function")
expect(typeof beeInstance.load).toBe("function")
expect(typeof beeInstance.loadStageMode).toBe("function")
expect(typeof beeInstance.loadWorkspace).toBe("function")
expect(typeof beeInstance.loadConfig).toBe("function")
})

test('should call getToken', () => {
const getTokenSpy = jest.spyOn(beeInstance, "getToken")

beeInstance.getToken('', '')
expect(getTokenSpy).toHaveBeenCalled()

})
})
Loading

0 comments on commit 0912604

Please sign in to comment.