...
 
Commits (6)
# html-validate changelog
## [2.8.2](https://gitlab.com/html-validate/html-validate/compare/v2.8.1...v2.8.2) (2020-01-09)
### Bug Fixes
- create directory only if missing ([5db6fe8](https://gitlab.com/html-validate/html-validate/commit/5db6fe8ad82ba04d691dec5aacfcba9be8aee759))
## [2.8.1](https://gitlab.com/html-validate/html-validate/compare/v2.8.0...v2.8.1) (2020-01-06)
### Bug Fixes
......
{
"name": "html-validate",
"version": "2.8.1",
"version": "2.8.2",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
......@@ -10160,9 +10160,9 @@
}
},
"front-matter": {
"version": "3.0.2",
"resolved": "https://registry.npmjs.org/front-matter/-/front-matter-3.0.2.tgz",
"integrity": "sha512-iBGZaWyzqgsrPGsqrXZP6N4hp5FzSKDi18nfAoYpgz3qK5sAwFv/ojmn3VS60SOgLvq6CtojNqy0y6ZNz05IzQ==",
"version": "3.1.0",
"resolved": "https://registry.npmjs.org/front-matter/-/front-matter-3.1.0.tgz",
"integrity": "sha512-RFEK8N6waWTdwBZOPNEtvwMjZ/hUfpwXkYUYkmmOhQGdhSulXhWrFwiUhdhkduLDiIwbROl/faF1X/PC/GGRMw==",
"dev": true,
"requires": {
"js-yaml": "^3.13.1"
......@@ -24077,9 +24077,9 @@
}
},
"sass": {
"version": "1.24.2",
"resolved": "https://registry.npmjs.org/sass/-/sass-1.24.2.tgz",
"integrity": "sha512-0JxdMMRd0fOmGFQFRI91vh4n0Ed766ib9JwPUa+1C37zn3VaqlHxbknUn/6LqP/MSfvNPxRYoCrYf5g8vu4OHw==",
"version": "1.24.3",
"resolved": "https://registry.npmjs.org/sass/-/sass-1.24.3.tgz",
"integrity": "sha512-RGpAeX0xAKUCcT9bNjVd2qcnqz9JkeDFXXLTclpuHJ4JfE8F1xC8SkasNroXqyDTRNFL4phPkvAN2Q8auAJfBQ==",
"dev": true,
"requires": {
"chokidar": ">=2.0.0 <4.0.0"
......@@ -25939,9 +25939,9 @@
"dev": true
},
"ts-jest": {
"version": "24.2.0",
"resolved": "https://registry.npmjs.org/ts-jest/-/ts-jest-24.2.0.tgz",
"integrity": "sha512-Yc+HLyldlIC9iIK8xEN7tV960Or56N49MDP7hubCZUeI7EbIOTsas6rXCMB4kQjLACJ7eDOF4xWEO5qumpKsag==",
"version": "24.3.0",
"resolved": "https://registry.npmjs.org/ts-jest/-/ts-jest-24.3.0.tgz",
"integrity": "sha512-Hb94C/+QRIgjVZlJyiWwouYUF+siNJHJHknyspaOcZ+OQAIdFG/UrdQVXw/0B8Z3No34xkUXZJpOTy9alOWdVQ==",
"dev": true,
"requires": {
"bs-logger": "0.x",
......
{
"name": "html-validate",
"version": "2.8.1",
"version": "2.8.2",
"description": "html linter",
"keywords": [
"html",
......@@ -127,7 +127,7 @@
"eslint-plugin-security": "1.4.0",
"eslint-plugin-sonarjs": "0.5.0",
"font-awesome": "4.7.0",
"front-matter": "3.0.2",
"front-matter": "3.1.0",
"grunt": "1.0.4",
"grunt-browserify": "5.3.0",
"grunt-cli": "1.3.2",
......@@ -146,11 +146,11 @@
"minimatch": "3.0.4",
"mkdirp": "0.5.1",
"prettier": "1.19.1",
"sass": "1.24.2",
"sass": "1.24.3",
"semantic-release": "15.14.0",
"serve-static": "1.14.1",
"strip-ansi": "6.0.0",
"ts-jest": "24.2.0",
"ts-jest": "24.3.0",
"tslint": "5.20.1",
"tslint-config-prettier": "1.18.0",
"typescript": "3.7.4"
......
......@@ -17,6 +17,18 @@ if [[ $? = 0 ]]; then
fi
echo "Testing if html-validate will save report to file"
mkdir -p temp
./bin/html-validate.js -f json=temp/report.json test-files/elements/table-valid.html
if [[ $? != 0 ]]; then
echo "Compatibility test failed, expected command to exit with zero status"
exit 1
fi
if [[ "$(cat temp/report.json)" != "[]" ]]; then
echo "Compatibility test failed, expected command to write report to file"
exit 1
fi
echo "Testing if html-validate will save report to file in subdirectory"
./bin/html-validate.js -f json=temp/compatibility/report.json test-files/elements/table-valid.html
if [[ $? != 0 ]]; then
echo "Compatibility test failed, expected command to exit with zero status"
......
......@@ -13,12 +13,17 @@ jest.mock("../formatters/json", () => {
return (report: Report) => jsonFormatter(report);
});
const mkdirSync = jest.fn();
const writeFileSync = jest.fn();
const fs = {
existsSync: jest.fn().mockReturnValue(true),
mkdirSync: jest.fn(),
writeFileSync: jest.fn(),
};
jest.mock("fs", () => {
return {
mkdirSync: (...args: any[]) => mkdirSync(...args),
writeFileSync: (...args: any[]) => writeFileSync(...args),
existsSync: (...args: any[]) => fs.existsSync(...args),
mkdirSync: (...args: any[]) => fs.mkdirSync(...args),
writeFileSync: (...args: any[]) => fs.writeFileSync(...args),
};
});
......@@ -66,10 +71,18 @@ describe("cli/formatters", () => {
expect(jsonFormatter).toHaveBeenCalledWith(report.results);
});
it("should redirect output", () => {
it("should redirect output to file", () => {
const wrapped = cli.getFormatter("text=foo.txt");
wrapped(report);
expect(fs.mkdirSync).not.toHaveBeenCalled();
expect(fs.writeFileSync).toHaveBeenCalledWith("foo.txt", "", "utf-8");
});
it("should create directory if missing", () => {
fs.existsSync.mockReturnValue(false);
const wrapped = cli.getFormatter("text=mydir/foo.txt");
wrapped(report);
expect(mkdirSync).toHaveBeenCalledWith("mydir", { recursive: true });
expect(writeFileSync).toHaveBeenCalledWith("mydir/foo.txt", "", "utf-8");
expect(fs.mkdirSync).toHaveBeenCalledWith("mydir", { recursive: true });
expect(fs.writeFileSync).toHaveBeenCalledWith("mydir/foo.txt", "", "utf-8");
});
});
......@@ -12,7 +12,10 @@ function wrap(
return (results: Result[]) => {
const output = formatter(results);
if (dst) {
fs.mkdirSync(path.dirname(dst), { recursive: true });
const dir = path.dirname(dst);
if (!fs.existsSync(dir)) {
fs.mkdirSync(dir, { recursive: true });
}
fs.writeFileSync(dst, output, "utf-8");
return null;
} else {
......