mirror of
https://github.com/wled/WLED.git
synced 2025-07-19 08:46:34 +00:00
Add test for -f and --force argument
This commit is contained in:
parent
e0facf35c8
commit
39fb7fdfe3
@ -114,6 +114,11 @@ describe('Script', () => {
|
||||
await checkIfBuiltFilesExist();
|
||||
}
|
||||
|
||||
async function checkIfFileWasNewlyCreated(file) {
|
||||
const modifiedTime = fs.statSync(file).mtimeMs;
|
||||
assert(Date.now() - modifiedTime < 500, file + ' was not modified');
|
||||
}
|
||||
|
||||
async function testFileModification(sourceFilePath, resultFile) {
|
||||
// run cdata.js to ensure html_*.h files are created
|
||||
await execPromise('node tools/cdata.js');
|
||||
@ -126,11 +131,7 @@ describe('Script', () => {
|
||||
// run script cdata.js again and wait for it to finish
|
||||
await execPromise('node tools/cdata.js');
|
||||
|
||||
// check if web ui was rebuilt
|
||||
const stats = fs.statSync(path.join(folderPath, resultFile));
|
||||
const modifiedTime = stats.mtimeMs;
|
||||
const currentTime = Date.now();
|
||||
assert(currentTime - modifiedTime < 500, resultFile + ' was not modified');
|
||||
checkIfFileWasNewlyCreated(path.join(folderPath, resultFile));
|
||||
}
|
||||
|
||||
describe('should build if', () => {
|
||||
@ -154,6 +155,16 @@ describe('Script', () => {
|
||||
await runAndCheckIfBuiltFilesExist();
|
||||
});
|
||||
|
||||
it('script was executed with -f or --force', async () => {
|
||||
await execPromise('node tools/cdata.js');
|
||||
await new Promise(resolve => setTimeout(resolve, 1000));
|
||||
await execPromise('node tools/cdata.js --force');
|
||||
await checkIfFileWasNewlyCreated(path.join(folderPath, 'html_ui.h'));
|
||||
await new Promise(resolve => setTimeout(resolve, 1000));
|
||||
await execPromise('node tools/cdata.js -f');
|
||||
await checkIfFileWasNewlyCreated(path.join(folderPath, 'html_ui.h'));
|
||||
});
|
||||
|
||||
it('a file changes', async () => {
|
||||
await testFileModification(path.join(dataPath, 'index.htm'), 'html_ui.h');
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user