Refractoring Stage 2 Add Refractor plan.md
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
const test = require('node:test');
|
||||
const assert = require('node:assert/strict');
|
||||
const fs = require('node:fs/promises');
|
||||
const path = require('node:path');
|
||||
|
||||
const root = path.resolve(__dirname, '..');
|
||||
const generated = path.join(root, 'www');
|
||||
const webAssetExtensions = new Set(['.css', '.html', '.js', '.svg', '.webmanifest']);
|
||||
|
||||
test('generated www web assets match their root source files', async () => {
|
||||
const entries = await fs.readdir(root, { withFileTypes: true });
|
||||
const assets = entries
|
||||
.filter(entry => entry.isFile() && webAssetExtensions.has(path.extname(entry.name)))
|
||||
.map(entry => entry.name);
|
||||
|
||||
assert.ok(assets.length > 0, 'expected root web assets to be present');
|
||||
|
||||
for (const asset of assets) {
|
||||
const sourcePath = path.join(root, asset);
|
||||
const generatedPath = path.join(generated, asset);
|
||||
const [source, output] = await Promise.all([
|
||||
fs.readFile(sourcePath),
|
||||
fs.readFile(generatedPath).catch(error => {
|
||||
if (error.code === 'ENOENT') {
|
||||
assert.fail(`generated web asset is missing: www/${asset}`);
|
||||
}
|
||||
throw error;
|
||||
})
|
||||
]);
|
||||
|
||||
assert.deepEqual(output, source, `www/${asset} is stale; rebuild Android web assets`);
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user