Merge pull request #1031 from balena-io/roman/use-resin-lint

Use resin-lint for mocha tests check
This commit is contained in:
Roman Mazur 2019-07-08 20:35:21 +03:00 committed by GitHub
commit e1fdafddfc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 11 additions and 50 deletions

View File

@ -7,4 +7,10 @@
"resin-lint --typescript --no-prettier", "resin-lint --typescript --no-prettier",
"git add" "git add"
], ],
"test/**/*.coffee": [
"resin-lint --tests"
],
"test/**/*.ts": [
"resin-lint --typescript --no-prettier --tests"
],
} }

View File

@ -1,45 +0,0 @@
#!/usr/bin/env node
// This script checks if files in test directory don't contain describe.only or it.only statements
// to ensure that an accidental commit does not prevent all the tests to be run.
const fs = require('fs');
const path = require('path');
const testsDir = './test';
const srcFileExtensions = ['.ts', '.coffee', '.js'];
const checkPattern = /((describe)|(it))\.only/;
const checkDirRecursively = (dirPath, func) =>
fs.readdirSync(dirPath, {withFileTypes: true}).forEach((file) => {
const filePath = path.join(dirPath, file.name);
if (file.isDirectory()) {
checkDirRecursively(filePath, func);
return;
}
for (let ext of srcFileExtensions) {
if (file.name.endsWith(ext)) {
const content = fs.readFileSync(filePath, {encoding: 'utf8'});
func(filePath, content);
break;
}
}
});
let errorsFound = false;
checkDirRecursively(testsDir, (fileName, content) => {
const lines = content.split('\n');
for (let ln = 0; ln < lines.length; ln++) {
const res = checkPattern.exec(lines[ln]);
if (res) {
errorsFound = true;
console.error(`File ${fileName}, line ${ln}: found ${res[0]}`);
}
}
});
if (errorsFound) {
process.exit(1);
}

6
package-lock.json generated
View File

@ -8783,9 +8783,9 @@
} }
}, },
"resin-lint": { "resin-lint": {
"version": "3.0.4", "version": "3.1.0",
"resolved": "https://registry.npmjs.org/resin-lint/-/resin-lint-3.0.4.tgz", "resolved": "https://registry.npmjs.org/resin-lint/-/resin-lint-3.1.0.tgz",
"integrity": "sha512-TVxY7SaJqQRZcLubJn5yO49db/M4eRXRr7FbA4xwqSYxQSqujNql8ThMoNMoRrx+1F7NrfSdhIsLEaMqCea4VA==", "integrity": "sha512-bipsVrhMBtoegrBdJf/6NMQke4g8xmZENSu0fBU1KvxLXNhGPQkmobY7vVmP47BeD0m0Zdv9yrEc43w2S+kRWA==",
"dev": true, "dev": true,
"requires": { "requires": {
"@types/bluebird": "^3.5.26", "@types/bluebird": "^3.5.26",

View File

@ -100,7 +100,7 @@
"prettier": "1.17.0", "prettier": "1.17.0",
"pretty-ms": "^4.0.0", "pretty-ms": "^4.0.0",
"request": "^2.51.0", "request": "^2.51.0",
"resin-lint": "^3.0.0", "resin-lint": "^3.1.0",
"resin-register-device": "^3.0.0", "resin-register-device": "^3.0.0",
"resumable-request": "^2.0.0", "resumable-request": "^2.0.0",
"rimraf": "^2.6.2", "rimraf": "^2.6.2",
@ -121,7 +121,7 @@
}, },
"husky": { "husky": {
"hooks": { "hooks": {
"pre-commit": "lint-staged && automation/lint-mocha-tests.js" "pre-commit": "lint-staged"
} }
} }
} }