flow like the river
This commit is contained in:
commit
013fe673f3
42435 changed files with 5764238 additions and 0 deletions
124
BACK_BACK/node_modules/@parcel/watcher/test/options.js
generated
vendored
Executable file
124
BACK_BACK/node_modules/@parcel/watcher/test/options.js
generated
vendored
Executable file
|
|
@ -0,0 +1,124 @@
|
|||
const Watcher = require('../index');
|
||||
const fs = require('@parcel/fs');
|
||||
const path = require('path');
|
||||
const assert = require('assert');
|
||||
const {sleep} = require('@parcel/test-utils');
|
||||
|
||||
describe('options', function() {
|
||||
let tmpFolder = path.join(__dirname, './tmp/');
|
||||
|
||||
before(() => {
|
||||
fs.mkdirp(tmpFolder);
|
||||
});
|
||||
|
||||
it('Should pass init options with correct ignored regex', async () => {
|
||||
let watcher = new Watcher({
|
||||
ignored: /file/
|
||||
});
|
||||
|
||||
let filepath = path.join(tmpFolder, 'file1.txt');
|
||||
await fs.writeFile(filepath, 'this is a text document');
|
||||
|
||||
watcher.add(filepath);
|
||||
|
||||
let changed = false;
|
||||
watcher.once('change', () => {
|
||||
changed = true;
|
||||
});
|
||||
|
||||
if (!watcher.ready) {
|
||||
await new Promise(resolve => watcher.once('ready', resolve));
|
||||
}
|
||||
|
||||
await sleep(250);
|
||||
|
||||
await fs.writeFile(filepath, 'this is not a text document');
|
||||
|
||||
await sleep(500);
|
||||
|
||||
assert(!changed, 'File should not be flagged as changed.');
|
||||
|
||||
await watcher.stop();
|
||||
});
|
||||
|
||||
it('Should pass init options with a more complex ignored regex', async () => {
|
||||
let watcher = new Watcher({
|
||||
ignored: /file|config/
|
||||
});
|
||||
|
||||
let filepaths = [
|
||||
path.join(tmpFolder, 'file1.txt'),
|
||||
path.join(tmpFolder, 'config.json')
|
||||
];
|
||||
|
||||
for (let filepath of filepaths) {
|
||||
await fs.writeFile(filepath, 'this is a text document');
|
||||
|
||||
watcher.add(filepath);
|
||||
}
|
||||
|
||||
let changed = false;
|
||||
watcher.once('change', () => {
|
||||
changed = true;
|
||||
});
|
||||
|
||||
if (!watcher.ready) {
|
||||
await new Promise(resolve => watcher.once('ready', resolve));
|
||||
}
|
||||
|
||||
await sleep(250);
|
||||
|
||||
for (let filepath of filepaths) {
|
||||
await fs.writeFile(filepath, 'this is not a text document');
|
||||
|
||||
watcher.add(filepath);
|
||||
}
|
||||
|
||||
await sleep(500);
|
||||
|
||||
assert(!changed, 'File should not be flagged as changed.');
|
||||
|
||||
await watcher.stop();
|
||||
});
|
||||
|
||||
it('Should not ignore any files outside of the regex', async () => {
|
||||
let watcher = new Watcher({
|
||||
ignored: /file|config/
|
||||
});
|
||||
|
||||
let filepaths = [
|
||||
path.join(tmpFolder, 'file1.txt'),
|
||||
path.join(tmpFolder, 'config.json'),
|
||||
path.join(tmpFolder, 'something')
|
||||
];
|
||||
|
||||
for (let filepath of filepaths) {
|
||||
await fs.writeFile(filepath, 'this is a text document');
|
||||
|
||||
watcher.add(filepath);
|
||||
}
|
||||
|
||||
let changed = 0;
|
||||
watcher.once('change', () => {
|
||||
changed++;
|
||||
});
|
||||
|
||||
if (!watcher.ready) {
|
||||
await new Promise(resolve => watcher.once('ready', resolve));
|
||||
}
|
||||
|
||||
await sleep(250);
|
||||
|
||||
for (let filepath of filepaths) {
|
||||
await fs.writeFile(filepath, 'this is not a text document');
|
||||
|
||||
watcher.add(filepath);
|
||||
}
|
||||
|
||||
await sleep(500);
|
||||
|
||||
assert.equal(changed, 1, 'One file should have changed once.');
|
||||
|
||||
await watcher.stop();
|
||||
});
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue