mirror of
https://github.com/balena-os/balena-supervisor.git
synced 2024-12-20 06:07:57 +00:00
36fa23ab7d
A simple script that detects presence of .only statements in tests. The idea is to avoid comitting them, so that all the tests are run with npm test. Change-type: patch Signed-off-by: Roman Mazur <roman@balena.io>
46 lines
1.2 KiB
JavaScript
Executable File
46 lines
1.2 KiB
JavaScript
Executable File
#!/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);
|
|
}
|