From bea97f47a7c2b5748ca50632a7de93f7f18af5fd Mon Sep 17 00:00:00 2001 From: Roman Mazur Date: Fri, 5 Jul 2019 13:59:44 +0300 Subject: [PATCH] Use resin-lint for mocha tests check Change-type: patch Signed-off-by: Roman Mazur --- .lintstagedrc | 6 +++++ automation/lint-mocha-tests.js | 45 ---------------------------------- package-lock.json | 6 ++--- package.json | 4 +-- 4 files changed, 11 insertions(+), 50 deletions(-) delete mode 100755 automation/lint-mocha-tests.js diff --git a/.lintstagedrc b/.lintstagedrc index 6a436119..42c209a7 100644 --- a/.lintstagedrc +++ b/.lintstagedrc @@ -7,4 +7,10 @@ "resin-lint --typescript --no-prettier", "git add" ], + "test/**/*.coffee": [ + "resin-lint --tests" + ], + "test/**/*.ts": [ + "resin-lint --typescript --no-prettier --tests" + ], } diff --git a/automation/lint-mocha-tests.js b/automation/lint-mocha-tests.js deleted file mode 100755 index 59ad0b41..00000000 --- a/automation/lint-mocha-tests.js +++ /dev/null @@ -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); -} diff --git a/package-lock.json b/package-lock.json index d486a6a2..5de739f3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -8783,9 +8783,9 @@ } }, "resin-lint": { - "version": "3.0.4", - "resolved": "https://registry.npmjs.org/resin-lint/-/resin-lint-3.0.4.tgz", - "integrity": "sha512-TVxY7SaJqQRZcLubJn5yO49db/M4eRXRr7FbA4xwqSYxQSqujNql8ThMoNMoRrx+1F7NrfSdhIsLEaMqCea4VA==", + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/resin-lint/-/resin-lint-3.1.0.tgz", + "integrity": "sha512-bipsVrhMBtoegrBdJf/6NMQke4g8xmZENSu0fBU1KvxLXNhGPQkmobY7vVmP47BeD0m0Zdv9yrEc43w2S+kRWA==", "dev": true, "requires": { "@types/bluebird": "^3.5.26", diff --git a/package.json b/package.json index 62a7343e..e8f0c652 100644 --- a/package.json +++ b/package.json @@ -100,7 +100,7 @@ "prettier": "1.17.0", "pretty-ms": "^4.0.0", "request": "^2.51.0", - "resin-lint": "^3.0.0", + "resin-lint": "^3.1.0", "resin-register-device": "^3.0.0", "resumable-request": "^2.0.0", "rimraf": "^2.6.2", @@ -121,7 +121,7 @@ }, "husky": { "hooks": { - "pre-commit": "lint-staged && automation/lint-mocha-tests.js" + "pre-commit": "lint-staged" } } }