I am currently using Jest, Husky, Commitizen, and Vuepress. However, when jest tests or the build fails, the commit hook still works. How can I fix this to exit the commitizen hook when things fail? Here is the relevant lines in package.json:
{
"scripts": {
"build": "vuepress build docs
"lint": "eslint --fix --ext .js,.vue docs/.vuepress",
"test": "npm run lint && jest --coverage --coverageDirectory='__coverage__'",
"test:full": "npm run test && npm run build",
"commit": "cz",
...
},
"husky": {
"hooks": {
"prepare-commit-msg": "npm run test:full && exec < /dev/tty && git cz --hook || true"
}
},
"dependencies": {
...
},
"devDependencies": {
"babel-jest": "^26.6.3",
"commitizen": "^4.2.3",
"cz-conventional-changelog": "^3.3.0",
"eslint": "^7.18.0",
"husky": "^4.3.8",
"jest": "^26.6.3",
...
},
"config": {
"commitizen": {
"path": "./node_modules/cz-conventional-changelog"
}
}
}
Figured it out - it was simple. I needed to add the following to husky:
"husky": {
"hooks": {
"pre-commit": "npm run test:full",
...
}
},
Related
I was trying to create a docker Image where it is getting stuck at the "npm run build" step. I could see the message as build completed successfully but it is not proceeding to the next step.
below the docker file. I m using node:16.13.1 as base Image
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
COPY package.json ./
COPY .npmrc ./
RUN npm install node-sass#latest
RUN npm install core-js#2.5.7
RUN npm install
COPY . /usr/src/app
# build web app
RUN npm run build
EXPOSE 8080
RUN chmod +x /usr/src/app/setup.sh
CMD ["/usr/src/app/setup.sh"]
Not proceeding after the below step,
Package.json file
{
"name": "full-kyc",
"version": "0.1.0",
"private": true,
"scripts": {
"serve": "vue-cli-service serve",
"build": "vue-cli-service build",
"lint": "vue-cli-service lint",
"format": "prettier --write \"**/*.{js,vue,html,json,md}\" && prettier-stylelint --write --quiet '**/*.{css,scss,vue}'",
"build:dev": "vue-cli-service build --mode development --watch",
"start:dev": "NODE_ENV=development nodemon bin/www | bunyan",
"start:prod": "node bin/www | bunyan"
},
"husky": {
"hooks": {
"pre-commit": "lint-staged"
}
},
"lint-staged": {
"*.{js,vue,html,json,md}": [
"prettier --write",
"git add"
],
"*.{css,scss,vue}": [
"prettier-stylelint --write --quiet",
"git add"
]
},
"dependencies": {
"#vue/babel-preset-app": "^4.5.15",
"axios": "^0.21.4",
"body-parser": "1.18.3",
"btoa": "^1.2.1",
"bunyan": "1.8.12",
"cookie-parser": "1.4.3",
"crypto": "^1.0.1",
"express": "4.16.3",
"express-http-proxy": "1.4.0",
"raven-js": "^3.27.2",
"vue": "2.5.17",
"vue-router": "3.0.1",
"vuex": "3.0.1"
},
"devDependencies": {
"#vue/cli-plugin-babel": "^4.5.15",
"#vue/cli-plugin-eslint": "3.0.1",
"#vue/cli-service": "3.0.1",
"babel-eslint": "^10.1.0",
"eslint": "^5.16.0",
"eslint-config-prettier": "^6.15.0",
"eslint-loader": "^2.2.1",
"eslint-plugin-prettier": "^3.4.1",
"eslint-plugin-vue": "^5.2.3",
"husky": "^3.1.0",
"lint-staged": "^9.5.0",
"node-sass": "^4.14.1",
"nodemon": "1.18.4",
"prettier": "^1.19.1",
"prettier-stylelint": "^0.4.2",
"sass-loader": "7.0.1",
"stylelint-config-recommended": "^2.2.0",
"vue-template-compiler": "2.5.17",
"vue-smooth-picker": "file:vue-smooth-picker",
"webpack-bundle-analyzer": "^4.5.0"
},
"eslintConfig": {
"root": true,
"env": {
"node": true,
"es6": true,
"browser": true
},
"extends": [
"plugin:vue/essential",
"eslint:recommended",
"prettier/vue",
"plugin:prettier/recommended"
],
"rules": {
"vue/component-name-in-template-casing": [
"error",
"PascalCase"
]
},
"globals": {
"axios": "readonly"
},
"parserOptions": {
"parser": "babel-eslint"
}
},
"stylelint": {
"rules": {
"no-descending-specificity": null
},
"extends": "stylelint-config-recommended"
},
"postcss": {
"plugins": {
"autoprefixer": {}
}
},
"browserslist": [
"> 1%",
"last 2 versions",
"not ie <= 8"
]
}
change
RUN npm run build
to
CMD ["npm", "run", "build"]
I keep getting this error:
error in ./node_modules/keytar/build/Release/keytar.node
Module parse failed: Unexpected character '�' (1:2)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
(Source code omitted for this binary file)
# ./node_modules/keytar/lib/keytar.js 1:13-52
# ./src/background.js
# multi ./src/background.js
I have background.js set as the main electron file in package.json because I'm using vue/vuetify with it which uses a main.js file as well.
{
"name": "project",
"version": "0.1.0",
"private": true,
"scripts": {
"serve": "vue-cli-service serve",
"build": "vue-cli-service build",
"lint": "vue-cli-service lint",
"electron:build": "vue-cli-service electron:build",
"electron:serve": "vue-cli-service electron:serve",
"postinstall": "electron-builder install-app-deps",
"postuninstall": "electron-builder install-app-deps"
},
"main": "background.js", // <------------------ see right here
"dependencies": {
"axios": "^0.19.0",
"core-js": "^3.4.3",
"jwt-decode": "^2.2.0",
"keytar": "^5.0.0",
"request": "^2.88.0",
"vue": "^2.6.10",
"vue-router": "^3.1.3",
"vuetify": "^2.1.0",
"vuex": "^3.1.2"
},
"devDependencies": {
"#vue/cli-plugin-babel": "^4.1.0",
"#vue/cli-plugin-eslint": "^4.1.0",
"#vue/cli-service": "^4.1.0",
"babel-eslint": "^10.0.3",
"electron": "^7.1.3",
"eslint": "^5.16.0",
"eslint-plugin-vue": "^5.0.0",
"node-loader": "^0.6.0",
"sass": "^1.19.0",
"sass-loader": "^8.0.0",
"vue-cli-plugin-electron-builder": "^1.4.3",
"vue-cli-plugin-vuetify": "^2.0.2",
"vue-template-compiler": "^2.6.10",
"vuetify-loader": "^1.3.0"
},
"eslintConfig": {
"root": true,
"env": {
"node": true
},
"extends": [
"plugin:vue/essential",
"eslint:recommended"
],
"rules": {},
"parserOptions": {
"parser": "babel-eslint"
}
},
"browserslist": [
"> 1%",
"last 2 versions"
]
}
Searching, it seems this happens when keytar is used in a renderer process. But background.js isn't a renderer process. Or am I missing something? I am completely new to electron.
I needed to mark keytar as external (as mentioned at https://nklayman.github.io/vue-cli-plugin-electron-builder/guide/guide.html#native-modules)
// vue.config.js
module.exports = {
pluginOptions: {
electronBuilder: {
// List native deps here if they don't work
externals: ['keytar']
}
}
}
Once I did that it worked properly.
Run appropriate loader (source).
yarn add node-loader -D
// vue.config.js
configureWebpack: {
devtool: 'source-map',
module: {
rules: [
{ test: /\.node$/, loader: 'node-loader' }
]
}
}
I have created an electron app .Using electron-builder I created appImage in linux.I want build app for windows in linux .But it is throwing wine required error .please help to resolve this issue.
this is package.json
"name": "Gamer",
"version": "1.0.0",
"main": "main.js",
"repository": "https://github.com/XYX/GAME",
"dependencies": {
"#agm/core": "^1.0.0-beta.5",
...
"electron-builder-squirrel-windows": "^22.1.0",
"electron-packager": "^14.1.0",
"electron-reload": "^1.5.0",
"electron-store": "^5.1.0",
},
"devDependencies": {
...
"electron": "^7.1.1",
"electron-builder": "^22.1.0",
"electron-prebuilt": "^1.4.13",
"electron-updater": "^4.2.0",
...
},
"scripts": {
"ng": "ng",
"start": "ng serve",
"start:electron": "ng build --base-href ./ && electron .",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e",
"electron": "electron .",
"electron-build": "ng build --prod && electron .",
"pack": "electron-builder --dir",
"dist": "electron-builder",
"build:Win": "electron-builder --win",
"ship": "build",
"electron-packager": "electron-packager ./ --all."
},
"peerDependencies": {
"#angular/animations": "^7.2.15",
"#angular/cdk": "^7.3.7",
"#angular/material": "^7.3.7"
},
"author": "",
"license": "ISC",
"build": {
"appId": "com.electron.coxGamer",
"compression": "normal",
"extends": null,
"files": [
"*.js",
"build",
"dist"
],
"mac": {
"target": "zip"
},
"linux": {
"target": [
"AppImage",
"zip"
]
},
"win": {
"target": "NSIS"
},
"publish": {
"provider": "github",
"repo": "https://github.com/XYX/GAME",
"owner": "XYX"
}
}
}
Even the electron-updater throwing error for dev-update.yml not found.and also app-icon is not setting
const { app, BrowserWindow, Menu,ipcMain } = require('electron');
const path = require('path');
const url = require('url');
const { autoUpdater } = require("electron-updater");
Menu.setApplicationMenu(null);
let mainWindow;
const createWindow = () => {
mainWindow = new BrowserWindow({
width: 1200,
height: 900
});
mainWindow.setMenuBarVisibility(false);
mainWindow.loadURL(url.format({
pathname: path.join(__dirname, 'dist', 'index.html'),
protocol: 'file:',
slashes: true
}));
mainWindow.on('closed', () => {
mainWindow = null;
});
};
autoUpdater.on('update-downloaded', (info) => {
win.webContents.send('updateReady')
});
app.on('ready', () => {
createWindow();
autoUpdater.checkForUpdates();
});
ipcMain.on("quitAndInstall", (event, arg) => {
autoUpdater.quitAndInstall();
});
app.on('window-all-closed', () => {
if (process.platform !== 'darwin')
app.quit();
});
app.on('activate', () => {
if (mainWindow === null) {
createWindow();
}
});
Here is how I managed to build windows app from mac/linux. Maybe this can help you #Krazy.
First off all, I'm using the docker version of electron-builder
And then, here are the steps
1- Install electron builder dev in your project
npm install electron-builder —save-dev
2- In package.json add this to script
"dist": "electron-builder"
3- Launch Docker
4- In terminal, run
docker run --rm -ti \
--env-file <(env | grep -iE 'DEBUG|NODE_|ELECTRON_|YARN_|NPM_|CI|CIRCLE|TRAVIS_TAG|TRAVIS|TRAVIS_REPO_|TRAVIS_BUILD_|TRAVIS_BRANCH|TRAVIS_PULL_REQUEST_|APPVEYOR_|CSC_|GH_|GITHUB_|BT_|AWS_|STRIP|BUILD_') \
--env ELECTRON_CACHE="/root/.cache/electron" \
--env ELECTRON_BUILDER_CACHE="/root/.cache/electron-builder" \
-v ${PWD}:/project \
-v ${PWD##*/}-node-modules:/project/node_modules \
-v ~/.cache/electron:/root/.cache/electron \
-v ~/.cache/electron-builder:/root/.cache/electron-builder \
electronuserland/builder:wine
5- cd into your project
6- type
yarn && yarn dist -w
This is how I build my first windows app in Linux.
1- Install electron builder dev in your project
npm install electron-builder
2- Create a builder.js file your should look like this.
const builder = require("electron-builder")
const Platform = builder.Platform
// Promise is returned
builder.build({
targets: Platform.WINDOWS.createTarget(),
config: {
'win': {
'files': [
// All your files you are using
'main.js',
],
'compression': 'store',
'asar': false
}
}
})
.then(() => {
// handle result
})
.catch((error) => {
// handle error
})
3- Launch your app.
I'm building a new project using Xcode and I get an error
react-native init test
{
"name": "test1",
"version": "0.0.1",
"private": true,
"scripts": {
"start": "node node_modules/react-native/local-cli/cli.js start",
"test": "jest"
},
"dependencies": {
"react": "16.8.3",
"react-native": "0.59.9"
},
"devDependencies": {
"#babel/core": "7.4.5",
"#babel/runtime": "7.4.5",
"babel-jest": "24.8.0",
"jest": "24.8.0",
"metro-react-native-babel-preset": "0.54.1",
"react-test-renderer": "16.8.3"
},
"jest": {
"preset": "react-native"
}
}
I got this error
'glog/logging.h' file not found
Try this:
rm -rf ./node_modules && yarn && react-native run-ios
cd node_modules/react-native/third-party/glog-0.3.4 && ../../scripts/ios-configure-glog.sh should do the trick.
You just have to execute the script manually. Might need to sudo.
I'm trying to setup codecov as code coverage tool in a repository. However, it is passing Travis CI test but not showing codecov report. Here is link of travis report - https://travis-ci.org/fossasia/susper.com/builds/213793203 (see under bash <(curl -s https://codecov.io/bash)). What should I do?
Here is the source code -
package.json
{
"name": "susper",
"version": "0.0.0",
"license": "MIT",
"angular-cli": {},
"scripts": {
"start": "ng serve",
"lint": "tslint \"src/**/*.ts\"",
"test": "ng test",
"pree2e": "webdriver-manager update",
"e2e": "protractor"
},
"private": true,
"dependencies": {
"#angular/common": "2.4.0",
"#angular/compiler": "2.4.0",
"#angular/core": "2.4.0",
"#angular/forms": "2.4.0",
"#angular/http": "2.4.0",
"#angular/platform-browser": "2.4.0",
"#angular/platform-browser-dynamic": "2.4.0",
"#angular/router": "3.4.0",
"#ngrx/core": "^1.2.0",
"#ngrx/effects": "^2.0.0",
"#ngrx/router-store": "^1.2.5",
"#ngrx/store": "^2.2.1",
"#ngrx/store-devtools": "^3.2.3",
"core-js": "^2.4.1",
"ngrx-store-freeze": "^0.1.6",
"reselect": "^2.5.4",
"rxjs": "5.0.0-beta.12",
"ts-helpers": "^1.1.1",
"zone.js": "^0.6.23"
},
"devDependencies": {
"#angular/compiler-cli": "2.4.0",
"#types/jasmine": "2.5.38",
"#types/node": "^6.0.42",
"angular-cli": "1.0.0-beta.24",
+ "codecov.io": "^0.1.6",
"codelyzer": "~2.0.0-beta.1",
"jasmine-core": "2.5.2",
"jasmine-spec-reporter": "2.5.0",
- "karma": "1.2.0",
+ "karma": "^1.2.0",
"karma-chrome-launcher": "^2.0.0",
"karma-cli": "^1.0.1",
+ "karma-coverage": "^1.1.1",
"karma-jasmine": "^1.0.2",
"karma-remap-istanbul": "^0.2.1",
"protractor": "4.0.9",
"ts-node": "1.2.1",
"tslint": "^4.0.2",
"typescript": "~2.0.3",
"webdriver-manager": "10.2.5"
}
}
travis.yml
sudo: required
dist: trusty
language: node_js
node_js:
- 6
before_install:
- export CHROME_BIN=chromium-browser
- export DISPLAY=:99.0
- sh -e /etc/init.d/xvfb start
+- pip install --user codecov
before_script:
- ng build
script:
- ng lint
- >
docker run -ti -v $(pwd):/app --workdir=/app coala/base coala --version
after_success:
- bash ./deploy.sh
+- bash <(curl -s https://codecov.io/bash)
cache:
bundler: true
directories:
- node_modules
- .coala-cache
services: docker
branches:
only:
- angular
karma.conf.js
// Karma configuration file, see link for more information
// https://karma-runner.github.io/0.13/config/configuration-file.html
module.exports = function (config) {
config.set({
basePath: '',
frameworks: ['jasmine', 'angular-cli'],
plugins: [
require('karma-jasmine'),
require('karma-chrome-launcher'),
require('karma-remap-istanbul'),
- require('angular-cli/plugins/karma')
+ require('angular-cli/plugins/karma'),
+ require('karma-coverage')
],
files: [
{ pattern: './src/test.ts', watched: false }
],
preprocessors: {
- './src/test.ts': ['angular-cli']
+ './src/test.ts': ['angular-cli'],
+ 'src/app/**/*.js': ['coverage']
},
mime: {
'text/x-typescript': ['ts','tsx']
},
remapIstanbulReporter: {
reports: {
html: 'coverage',
lcovonly: './coverage/coverage.lcov'
}
},
+ coverageReporter: {
+ type : 'lcov',
+ dir : 'coverage/'
+ },
angularCli: {
config: './angular-cli.json',
environment: 'dev'
},
reporters: config.angularCli && config.angularCli.codeCoverage
? ['progress', 'karma-remap-istanbul']
- : ['progress'],
+ : ['progress', 'coverage'],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: ['Chrome'],
singleRun: false
});
};
tsconfig.json
{
"compilerOptions": {
"baseUrl": "",
"declaration": false,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"lib": ["es6", "dom"],
"mapRoot": "./",
"module": "es6",
"moduleResolution": "node",
"outDir": "../dist/out-tsc",
"sourceMap": true,
"target": "es5",
"typeRoots": [
"../node_modules/#types"
]
}
}
Happy to help out!
Issue: No reports are generated. See https://travis-ci.org/fossasia/susper.com/builds/213793203#L390
Suggestions
You do not need to use the bash uploader and the node uploader in the same project. So you may choose one or the other. Nonetheless, you have configured Codecov properly.
Using Docker: http://docs.codecov.io/docs/testing-with-docker
I did not dive deep into your project, but I suspect the reports are within the docker container and need to be passed through to Travis.