Add webpack-based js tests
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
This commit is contained in:
parent
fc18116715
commit
b267409d38
6 changed files with 1167 additions and 2 deletions
17
.github/workflows/node.yml
vendored
17
.github/workflows/node.yml
vendored
|
@ -31,3 +31,20 @@ jobs:
|
||||||
bash -c "[[ ! \"`git status --porcelain `\" ]] || ( echo 'Uncommited changes in webpack build' && git status && exit 1 )"
|
bash -c "[[ ! \"`git status --porcelain `\" ]] || ( echo 'Uncommited changes in webpack build' && git status && exit 1 )"
|
||||||
env:
|
env:
|
||||||
CI: true
|
CI: true
|
||||||
|
|
||||||
|
test:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
node-version: [12.x]
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
- name: Use node ${{ matrix.node-version }}
|
||||||
|
uses: actions/setup-node@v1
|
||||||
|
with:
|
||||||
|
node-version: ${{ matrix.node-version }}
|
||||||
|
- name: Install dependencies
|
||||||
|
run: |
|
||||||
|
npm ci
|
||||||
|
- name: Test
|
||||||
|
run: npm run test
|
||||||
|
|
48
core/src/tests/OC/requesttoken.spec.js
Normal file
48
core/src/tests/OC/requesttoken.spec.js
Normal file
|
@ -0,0 +1,48 @@
|
||||||
|
/*
|
||||||
|
* @copyright 2020 Christoph Wurst <christoph@winzerhof-wurst.at>
|
||||||
|
*
|
||||||
|
* @author 2020 Christoph Wurst <christoph@winzerhof-wurst.at>
|
||||||
|
*
|
||||||
|
* @license GNU AGPL version 3 or any later version
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License as
|
||||||
|
* published by the Free Software Foundation, either version 3 of the
|
||||||
|
* License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Affero General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import {subscribe, unsubscribe} from '@nextcloud/event-bus'
|
||||||
|
|
||||||
|
import {setToken} from '../../OC/requesttoken'
|
||||||
|
|
||||||
|
describe('request token', () => {
|
||||||
|
|
||||||
|
describe('@nextcloud/auth integration', () => {
|
||||||
|
let listener
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
listener = sinon.spy()
|
||||||
|
|
||||||
|
subscribe('csrf-token-update', listener)
|
||||||
|
})
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
unsubscribe('csrf-token-update', listener)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('fires off an event for @nextcloud/auth', () => {
|
||||||
|
setToken('123')
|
||||||
|
|
||||||
|
expect(listener).to.have.been.calledWith({token: '123'})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
})
|
36
core/src/tests/setup.js
Normal file
36
core/src/tests/setup.js
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
/*
|
||||||
|
* @copyright 2018 Christoph Wurst <christoph@winzerhof-wurst.at>
|
||||||
|
*
|
||||||
|
* @author 2018 Christoph Wurst <christoph@winzerhof-wurst.at>
|
||||||
|
*
|
||||||
|
* @license GNU AGPL version 3 or any later version
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License as
|
||||||
|
* published by the Free Software Foundation, either version 3 of the
|
||||||
|
* License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Affero General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
require('jsdom-global')()
|
||||||
|
const chai = require('chai')
|
||||||
|
var sinon = require('sinon')
|
||||||
|
var sinonChai = require('sinon-chai');
|
||||||
|
|
||||||
|
chai.use(sinonChai)
|
||||||
|
global.expect = chai.expect
|
||||||
|
global.sinon = sinon
|
||||||
|
|
||||||
|
// https://github.com/vuejs/vue-test-utils/issues/936
|
||||||
|
// better fix for "TypeError: Super expression must either be null or
|
||||||
|
// a function" than pinning an old version of prettier.
|
||||||
|
//
|
||||||
|
// https://github.com/vuejs/vue-cli/issues/2128#issuecomment-453109575
|
||||||
|
window.Date = Date
|
31
core/webpack.test.js
Normal file
31
core/webpack.test.js
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
/*
|
||||||
|
* @copyright 2018 Christoph Wurst <christoph@winzerhof-wurst.at>
|
||||||
|
*
|
||||||
|
* @author 2018 Christoph Wurst <christoph@winzerhof-wurst.at>
|
||||||
|
*
|
||||||
|
* @license GNU AGPL version 3 or any later version
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License as
|
||||||
|
* published by the Free Software Foundation, either version 3 of the
|
||||||
|
* License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Affero General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
const merge = require('webpack-merge');
|
||||||
|
const common = require('./webpack.js');
|
||||||
|
// webpack.config.js
|
||||||
|
const nodeExternals = require('webpack-node-externals')
|
||||||
|
|
||||||
|
module.exports = merge(common[0], {
|
||||||
|
mode: 'development',
|
||||||
|
devtool: 'inline-cheap-module-source-map',
|
||||||
|
externals: [nodeExternals()]
|
||||||
|
})
|
1023
package-lock.json
generated
1023
package-lock.json
generated
File diff suppressed because it is too large
Load diff
14
package.json
14
package.json
|
@ -12,7 +12,9 @@
|
||||||
"dev": "NODE_ENV=development webpack --progress --config webpack.dev.js",
|
"dev": "NODE_ENV=development webpack --progress --config webpack.dev.js",
|
||||||
"watch": "NODE_ENV=development webpack --progress --watch --config webpack.dev.js",
|
"watch": "NODE_ENV=development webpack --progress --watch --config webpack.dev.js",
|
||||||
"lint:fix": "ESLINT_FIX=true webpack --progress --config webpack.dev.js",
|
"lint:fix": "ESLINT_FIX=true webpack --progress --config webpack.dev.js",
|
||||||
"lint:fix-watch": "ESLINT_FIX=true webpack --progress --watch --config webpack.dev.js"
|
"lint:fix-watch": "ESLINT_FIX=true webpack --progress --watch --config webpack.dev.js",
|
||||||
|
"test": "mochapack --webpack-config core/webpack.test.js --require core/src/tests/setup.js \"core/src/tests/**/*.spec.js\"",
|
||||||
|
"test:watch": "mochapack -w --webpack-config core/webpack.test.js --require core/src/tests/setup.js \"core/src/tests/**/*.spec.js\""
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
|
@ -87,6 +89,7 @@
|
||||||
"babel-eslint": "^10.0.3",
|
"babel-eslint": "^10.0.3",
|
||||||
"babel-loader": "^8.0.6",
|
"babel-loader": "^8.0.6",
|
||||||
"babel-plugin-transform-es2015-arrow-functions": "^6.22.0",
|
"babel-plugin-transform-es2015-arrow-functions": "^6.22.0",
|
||||||
|
"chai": "^4.2.0",
|
||||||
"css-loader": "^3.4.1",
|
"css-loader": "^3.4.1",
|
||||||
"eslint": "^5.16.0",
|
"eslint": "^5.16.0",
|
||||||
"eslint-config-nextcloud": "0.1.1",
|
"eslint-config-nextcloud": "0.1.1",
|
||||||
|
@ -101,15 +104,22 @@
|
||||||
"exports-loader": "^0.7.0",
|
"exports-loader": "^0.7.0",
|
||||||
"file-loader": "^5.0.2",
|
"file-loader": "^5.0.2",
|
||||||
"handlebars-loader": "^1.7.1",
|
"handlebars-loader": "^1.7.1",
|
||||||
|
"jsdom": "^16.1.0",
|
||||||
|
"jsdom-global": "^3.0.2",
|
||||||
|
"mocha": "^7.0.1",
|
||||||
|
"mochapack": "^1.1.13",
|
||||||
"node-sass": "^4.13.1",
|
"node-sass": "^4.13.1",
|
||||||
"sass-loader": "^8.0.2",
|
"sass-loader": "^8.0.2",
|
||||||
|
"sinon": "^8.1.1",
|
||||||
|
"sinon-chai": "^3.4.0",
|
||||||
"style-loader": "^1.1.3",
|
"style-loader": "^1.1.3",
|
||||||
"url-loader": "^3.0.0",
|
"url-loader": "^3.0.0",
|
||||||
"vue-loader": "^15.8.3",
|
"vue-loader": "^15.8.3",
|
||||||
"vue-template-compiler": "^2.6.11",
|
"vue-template-compiler": "^2.6.11",
|
||||||
"webpack": "^4.41.5",
|
"webpack": "^4.41.5",
|
||||||
"webpack-cli": "^3.3.10",
|
"webpack-cli": "^3.3.10",
|
||||||
"webpack-merge": "^4.2.2"
|
"webpack-merge": "^4.2.2",
|
||||||
|
"webpack-node-externals": "^1.7.2"
|
||||||
},
|
},
|
||||||
"browserslist": [
|
"browserslist": [
|
||||||
"extends @nextcloud/browserslist-config"
|
"extends @nextcloud/browserslist-config"
|
||||||
|
|
Loading…
Reference in a new issue