feat(test): add test harness and tests

This commit is contained in:
Daniel Thompson-Yvetot
2019-12-16 00:47:23 +01:00
parent 91fa566ee8
commit e8eb8369e0
11 changed files with 2804 additions and 41 deletions

9
.editorconfig Normal file
View File

@@ -0,0 +1,9 @@
root = true
[*]
charset = utf-8
indent_style = space
indent_size = 2
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true

1
.env.jest Normal file
View File

@@ -0,0 +1 @@
NODE_ENV=test

19
.github/sanity-test-webpack vendored Normal file
View File

@@ -0,0 +1,19 @@
name: Sanity Test
on: [push]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- name: Use Node.js 12.x
uses: actions/setup-node@master
with:
node-version: 12.x
- name: Install and build
run: |
yarn install --frozen-lockfile
yarn test

10
.npmignore Normal file
View File

@@ -0,0 +1,10 @@
test
node_modules
.git
.github
.idea
SECURITY.md
.env.jest
.eslintrc.js
jest.config.js
renovate.json

35
jest.config.js Normal file
View File

@@ -0,0 +1,35 @@
module.exports = {
globals: {
__DEV__: true
},
setupFilesAfterEnv: ['<rootDir>/test/jest/jest.setup.js'],
// noStackTrace: true,
// bail: true,
// cache: false,
// verbose: true,
// watch: true,
collectCoverage: true,
coverageDirectory: '<rootDir>/test/jest/coverage',
collectCoverageFrom: [
'<rootDir>/plugins/*.js',
'<rootDir>/index.js'
],
coverageReporters: ['json-summary', 'text', 'lcov'],
coverageThreshold: {
global: {
// branches: 50,
// functions: 50,
// lines: 50,
// statements: 50
}
},
testMatch: [
'<rootDir>/test/jest/__tests__/**/*.spec.js'
],
moduleFileExtensions: ['js', 'json'],
moduleNameMapper: {
'^~/(.*)$': '<rootDir>/$1',
'^plugins/(.*)$': '<rootDir>/plugins/$1'
},
transform: {}
}

View File

@@ -4,27 +4,40 @@
"description": "Webpack configuration for Tauri.",
"main": "index.js",
"scripts": {
"test": "jest",
"lint-fix": "eslint --fix ./plugins/*.js ./*.js",
"lint:lockfile": "lockfile-lint --path yarn.lock --type yarn --validate-https --allowed-hosts npm yarn"
},
"funding": {
"type": "opencollective",
"url": "https://opencollective.com/tauri"
},
"repository": {
"type": "git",
"url": "git+https://github.com/tauri-apps/tauri.git"
"url": "git+https://github.com/tauri-apps/tauri-webpack.git"
},
"keywords": [
"tauri",
"webpack"
],
"author": "Lucas Nogueira <lucas@quasar.dev>",
"contributors": [
"Tauri Team <team@tauri-apps.org> (https://tauri-apps.org)",
"Lucas Fernandes Gonçalves Nogueira <lucas@quasar.dev>",
"Daniel Thompson-Yvetot <denjell@sfosc.org>"
],
"license": "MIT",
"bugs": {
"url": "https://github.com/tauri-apps/tauri/issues"
"url": "https://github.com/tauri-apps/tauri-webpack/issues"
},
"homepage": "https://github.com/tauri-apps/tauri#readme",
"homepage": "https://github.com/tauri-apps/tauri-webpack#readme",
"dependencies": {
"webpack-shell-plugin": "^0.5.0"
"webpack-shell-plugin": "0.5.0"
},
"publishConfig": {
"access": "public"
},
"devDependencies": {
"dotenv": "8.2.0",
"eslint": "6.7.2",
"eslint-config-standard": "14.1.0",
"eslint-plugin-import": "2.19.1",
@@ -33,7 +46,25 @@
"eslint-plugin-promise": "4.2.1",
"eslint-plugin-security": "1.4.0",
"eslint-plugin-standard": "4.0.1",
"husky": "3.1.0",
"jest": "24.9.0",
"jest-mock-process": "1.2.0",
"lint-staged": "9.5.0",
"lockfile-lint": "3.0.3"
"lockfile-lint": "3.0.3",
"promise": "8.0.3"
},
"husky": {
"hooks": {
"pre-commit": "lint-staged"
}
},
"lint-staged": [
"eslint --fix",
"git add"
],
"engines": {
"node": ">= 10.17.0",
"npm": ">= 6.6.0",
"yarn": ">= 1.19.1"
}
}

View File

@@ -1,3 +1,7 @@
/**
* @module TauriRequirePlugin
* @description Webpack tool for loading chunks in tauri
*/
module.exports.plugin = class TauriRequirePlugin {
apply (compiler) {
compiler.plugin('compilation', function (compilation) {

View File

@@ -0,0 +1,15 @@
// eslint-disable-next-line node/no-missing-require
const Chainer = require('plugins/tauri-require.js').plugin
describe('index.js', () => {
it('is a proper function', () => {
const test = typeof Chainer
expect(test).toBe('function')
})
/*
it('has a function', () => {
const test = new Chainer({ automaticStart: true })
expect(test).toBe('object')
})
*/
})

View File

@@ -0,0 +1,44 @@
// eslint-disable-next-line node/no-missing-require
const TauriRequirePlugin = require('plugins/tauri-require.js').plugin
describe('index.js', () => {
it('is a function', () => {
const test = typeof TauriRequirePlugin
expect(test).toBe('function')
})
it('can use the `new` keyword', () => {
const test = new TauriRequirePlugin()
expect(typeof test).toBe('object')
})
it('is a proper object', async () => {
const tauri = new TauriRequirePlugin({})
try {
await tauri.apply()
} catch (e) {
expect(e.message).toBe("Cannot read property 'plugin' of undefined")
}
})
/*
const compiler = (mock) => {
return {
plugin: (mock, cb) => {
return cb(mock)
}
}
}
const mock = {
mainTemplate: {
hooks: {
requireEnsure: {
tap: () => {}
}
}
}
}
it('is a proper object', () => {
const test = new TauriRequirePlugin()
test.apply(compiler(mock))
expect(test.apply(compiler)).toBe('object')
})
*/
})

9
test/jest/jest.setup.js Normal file
View File

@@ -0,0 +1,9 @@
jest.setTimeout(1000)
global.Promise = require('promise')
setTimeout(() => {
// do nothing
}, 1)
require('dotenv').config({ path: '.env.jest' })

2656
yarn.lock

File diff suppressed because it is too large Load Diff