Add Prettier (#3011)

Consistent code formatting!
(it fixed a few minor bugs too)
This commit is contained in:
Christian Oliff
2023-09-08 05:20:47 +09:00
committed by GitHub
parent c0084e2c57
commit 29d7d8054b
30 changed files with 536 additions and 557 deletions

View File

@@ -9,21 +9,17 @@ 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'});
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) {
while (matchFound !== true && (character = readStream.read(1)) !== null) {
if (character === string.charAt(matchedPositions)) {
matchedPositions += 1;
} else {
@@ -33,31 +29,24 @@ function checkString(file, string, done) {
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();

View File

@@ -7,12 +7,9 @@ const require = createRequire(import.meta.url);
const pkg = require('../package.json');
const dirs = pkg['h5bp-configs'].directories;
const expectedFilesInArchiveDir = [
`${pkg.name}_v${pkg.version}.zip`
];
const expectedFilesInArchiveDir = [`${pkg.name}_v${pkg.version}.zip`];
const expectedFilesInDistDir = [
'.editorconfig',
'.gitattributes',
'.gitignore',
@@ -22,7 +19,7 @@ const expectedFilesInDistDir = [
'webpack.common.js',
'webpack.config.dev.js',
'webpack.config.prod.js',
'css/', // for directories, a `/` character
// should be included at the end
'css/style.css',
@@ -45,37 +42,34 @@ const expectedFilesInDistDir = [
'robots.txt',
'site.webmanifest',
'tile-wide.png',
'tile.png'
'tile.png',
];
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function checkFiles(directory, expectedFiles) {
// Get the list of files from the specified directory
const files = globSync('**/*', {
'cwd': directory,
'ignore': [
cwd: directory,
ignore: [
'**/node_modules/**',
'package-lock.json',
'**/dist/**',
'**/.cache/**',
],
'dot': true, // include hidden files
'mark': true // add a `/` character to directory matches
dot: true, // include hidden files
mark: true, // add a `/` character to directory matches
});
// Check if all expected files are present in the
// specified directory, and are of the expected type
expectedFiles.forEach((file) => {
let ok = false;
const expectedFileType = (file.slice(-1) !== '/' ? 'regular file' : 'directory');
const expectedFileType =
file.slice(-1) !== '/' ? 'regular file' : 'directory';
// If file exists
if (files.indexOf(file) !== -1) {
// Check if the file is of the correct type
if (file.slice(-1) !== '/') {
// Check if the file is really a regular file
@@ -84,35 +78,32 @@ function checkFiles(directory, expectedFiles) {
// Check if the file is a directory
// (Since glob adds the `/` character to directory matches,
// we can simply check if the `/` character is present)
ok = (files[files.indexOf(file)].slice(-1) === '/');
ok = files[files.indexOf(file)].slice(-1) === '/';
}
}
it(`"${file}" should be present and it should be a ${expectedFileType}`, () =>{
it(`"${file}" should be present and it should be a ${expectedFileType}`, () => {
assert.equal(true, ok);
});
});
// List all files that should be NOT
// be present in the specified directory
(files.filter((file) => {
return expectedFiles.indexOf(file) === -1;
})).forEach((file) => {
it(`"${file}" should NOT be present`, () => {
assert(false);
files
.filter((file) => {
return expectedFiles.indexOf(file) === -1;
})
.forEach((file) => {
it(`"${file}" should NOT be present`, () => {
assert(false);
});
});
});
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function runTests() {
describe('Test if all the expected files, and only them, are present in the build directories', () => {
describe(dirs.archive, () => {
checkFiles(dirs.archive, expectedFilesInArchiveDir);
});
@@ -120,9 +111,7 @@ function runTests() {
describe(dirs.dist, () => {
checkFiles(dirs.dist, expectedFilesInDistDir);
});
});
}
runTests();