Files
html5-boilerplate/test/file_content.mjs
Christian Oliff 29d7d8054b Add Prettier (#3011)
Consistent code formatting!
(it fixed a few minor bugs too)
2023-09-07 16:20:47 -04:00

53 lines
1.5 KiB
JavaScript

import assert from 'assert';
import fs from 'fs';
import path from 'path';
import { createRequire } from 'module';
const require = createRequire(import.meta.url);
const pkg = require('../package.json');
const dirs = pkg['h5bp-configs'].directories;
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function checkString(file, string, done) {
let character = '';
let matchFound = false;
let matchedPositions = 0;
const readStream = fs.createReadStream(file, { encoding: 'utf8' });
readStream.on('close', done);
readStream.on('error', done);
readStream.on('readable', function () {
// Read file until the string is found
// or the whole file has been read
while (matchFound !== true && (character = readStream.read(1)) !== null) {
if (character === string.charAt(matchedPositions)) {
matchedPositions += 1;
} else {
matchedPositions = 0;
}
if (matchedPositions === string.length) {
matchFound = true;
}
}
assert.equal(true, matchFound);
this.close();
});
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function runTests() {
const dir = dirs.dist;
describe(`Test if the files from the "${dir}" directory have the expected content`, () => {
it('"style.css" should contain a custom banner', function (done) {
const string = `/*! HTML5 Boilerplate v${pkg.version} | ${pkg.license} License | ${pkg.homepage} */\n`;
checkString(path.resolve(dir, 'css/style.css'), string, done);
});
});
}
runTests();