-
-
Notifications
You must be signed in to change notification settings - Fork 34.5k
test: split test-fs-watch-ignore-* #61494
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| import * as common from '../common/index.mjs'; | ||
| import { skipIfNoWatch } from '../common/watch.js'; | ||
|
|
||
| skipIfNoWatch(); | ||
|
|
||
| // if (common.isSunOS) | ||
| // common.skip('`fs.watch()` is not reliable on SunOS.'); | ||
|
|
||
| const assert = await import('node:assert'); | ||
| const path = await import('node:path'); | ||
| const tmpdir = await import('../common/tmpdir.js'); | ||
| const { watch } = await import('node:fs/promises'); | ||
| const { writeFileSync } = await import('node:fs'); | ||
|
|
||
| tmpdir.refresh(); | ||
|
|
||
| const testDir = tmpdir.resolve(); | ||
| const keepFile = 'visible.txt'; | ||
| const ignoreFile = '.hidden'; | ||
| const keepFilePath = path.join(testDir, keepFile); | ||
| const ignoreFilePath = path.join(testDir, ignoreFile); | ||
|
|
||
| const watcher = watch(testDir, { | ||
| ignore: (filename) => filename.startsWith('.'), | ||
| }); | ||
|
|
||
| // Do the write with a delay to ensure that the OS is ready to notify us. See | ||
| // https://github.com/nodejs/node/issues/52601. | ||
|
Comment on lines
+27
to
+28
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't know if the delay is needed only on macOS. If so, it would be better to conditionally delay writing using
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think on macOS at least, this is needed, otherwise it's known to cause flakes due to FSEvents coalescing. Not sure about other platforms. |
||
| setTimeout(() => { | ||
| writeFileSync(ignoreFilePath, 'ignored'); | ||
| writeFileSync(keepFilePath, 'content'); | ||
| }, common.platformTimeout(100)); | ||
|
|
||
| for await (const { filename } of watcher) { | ||
| assert.notStrictEqual(filename, ignoreFile); | ||
|
|
||
| if (filename === keepFile) { | ||
| break; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| import * as common from '../common/index.mjs'; | ||
| import { skipIfNoWatch } from '../common/watch.js'; | ||
|
|
||
| skipIfNoWatch(); | ||
|
|
||
| // if (common.isSunOS) | ||
| // common.skip('`fs.watch()` is not reliable on SunOS.'); | ||
|
|
||
| const assert = await import('node:assert'); | ||
| const path = await import('node:path'); | ||
| const tmpdir = await import('../common/tmpdir.js'); | ||
| const { watch } = await import('node:fs/promises'); | ||
| const { writeFileSync } = await import('node:fs'); | ||
|
|
||
| tmpdir.refresh(); | ||
|
|
||
| const testDir = tmpdir.resolve(); | ||
| const keepFile = 'keep.txt'; | ||
| const ignoreFile = 'ignore.log'; | ||
| const keepFilePath = path.join(testDir, keepFile); | ||
| const ignoreFilePath = path.join(testDir, ignoreFile); | ||
|
|
||
| const watcher = watch(testDir, { ignore: '*.log' }); | ||
|
|
||
| // Do the write with a delay to ensure that the OS is ready to notify us. See | ||
| // https://github.com/nodejs/node/issues/52601. | ||
| setTimeout(() => { | ||
| writeFileSync(ignoreFilePath, 'ignored'); | ||
| writeFileSync(keepFilePath, 'content'); | ||
| }, common.platformTimeout(100)); | ||
|
|
||
| for await (const { filename } of watcher) { | ||
| assert.notStrictEqual(filename, ignoreFile); | ||
|
|
||
| if (filename === keepFile) { | ||
| break; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| import '../common/index.mjs'; | ||
| import { skipIfNoWatch } from '../common/watch.js'; | ||
|
|
||
| skipIfNoWatch(); | ||
|
|
||
| const assert = await import('node:assert'); | ||
| const { watch } = await import('node:fs/promises'); | ||
|
|
||
| await assert.rejects( | ||
| async () => { | ||
| const watcher = watch('.', { ignore: 123 }); | ||
| // eslint-disable-next-line no-unused-vars | ||
| for await (const _ of watcher) { | ||
| // Will throw before yielding | ||
| } | ||
| }, | ||
| { | ||
| code: 'ERR_INVALID_ARG_TYPE', | ||
| name: 'TypeError', | ||
| } | ||
| ); | ||
|
|
||
| await assert.rejects( | ||
| async () => { | ||
| const watcher = watch('.', { ignore: '' }); | ||
| // eslint-disable-next-line no-unused-vars | ||
| for await (const _ of watcher) { | ||
| // Will throw before yielding | ||
| } | ||
| }, | ||
| { | ||
| code: 'ERR_INVALID_ARG_VALUE', | ||
| name: 'TypeError', | ||
| } | ||
| ); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| import * as common from '../common/index.mjs'; | ||
| import { skipIfNoWatch } from '../common/watch.js'; | ||
|
|
||
| skipIfNoWatch(); | ||
|
|
||
| // if (common.isSunOS) | ||
| // common.skip('`fs.watch()` is not reliable on SunOS.'); | ||
|
|
||
| const assert = await import('node:assert'); | ||
| const path = await import('node:path'); | ||
| const tmpdir = await import('../common/tmpdir.js'); | ||
| const { watch } = await import('node:fs/promises'); | ||
| const { writeFileSync } = await import('node:fs'); | ||
|
|
||
| tmpdir.refresh(); | ||
|
|
||
| const testDir = tmpdir.resolve(); | ||
| const keepFile = 'keep.txt'; | ||
| const ignoreLog = 'debug.log'; | ||
| const ignoreTmp = 'temp.tmp'; | ||
| const keepFilePath = path.join(testDir, keepFile); | ||
| const ignoreLogPath = path.join(testDir, ignoreLog); | ||
| const ignoreTmpPath = path.join(testDir, ignoreTmp); | ||
|
|
||
| const watcher = watch(testDir, { | ||
| ignore: [ | ||
| '*.log', | ||
| /\.tmp$/, | ||
| ], | ||
| }); | ||
|
|
||
| // Do the write with a delay to ensure that the OS is ready to notify us. See | ||
| // https://github.com/nodejs/node/issues/52601. | ||
| setTimeout(() => { | ||
| writeFileSync(ignoreLogPath, 'ignored'); | ||
| writeFileSync(ignoreTmpPath, 'ignored'); | ||
| writeFileSync(keepFilePath, 'content'); | ||
| }, common.platformTimeout(100)); | ||
|
|
||
| for await (const { filename } of watcher) { | ||
| assert.notStrictEqual(filename, ignoreLog); | ||
| assert.notStrictEqual(filename, ignoreTmp); | ||
|
|
||
| if (filename === keepFile) { | ||
| break; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| import * as common from '../common/index.mjs'; | ||
| import { skipIfNoWatch } from '../common/watch.js'; | ||
|
|
||
| skipIfNoWatch(); | ||
|
|
||
| // if (common.isSunOS) | ||
| // common.skip('`fs.watch()` is not reliable on SunOS.'); | ||
|
|
||
| const assert = await import('node:assert'); | ||
| const path = await import('node:path'); | ||
| const tmpdir = await import('../common/tmpdir.js'); | ||
| const { watch } = await import('node:fs/promises'); | ||
| const { writeFileSync } = await import('node:fs'); | ||
|
|
||
| tmpdir.refresh(); | ||
|
|
||
| const testDir = tmpdir.resolve(); | ||
| const keepFile = 'keep.txt'; | ||
| const ignoreFile = 'ignore.tmp'; | ||
| const keepFilePath = path.join(testDir, keepFile); | ||
| const ignoreFilePath = path.join(testDir, ignoreFile); | ||
|
|
||
| const watcher = watch(testDir, { ignore: /\.tmp$/ }); | ||
|
|
||
| // Do the write with a delay to ensure that the OS is ready to notify us. See | ||
| // https://github.com/nodejs/node/issues/52601. | ||
| setTimeout(() => { | ||
| writeFileSync(ignoreFilePath, 'ignored'); | ||
| writeFileSync(keepFilePath, 'content'); | ||
| }, common.platformTimeout(100)); | ||
|
|
||
| for await (const { filename } of watcher) { | ||
| assert.notStrictEqual(filename, ignoreFile); | ||
|
|
||
| if (filename === keepFile) { | ||
| break; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| 'use strict'; | ||
|
|
||
| const common = require('../common'); | ||
| const { skipIfNoWatch } = require('../common/watch.js'); | ||
|
|
||
| skipIfNoWatch(); | ||
|
|
||
| // if (common.isSunOS) | ||
| // common.skip('`fs.watch()` is not reliable on SunOS.'); | ||
|
|
||
| const assert = require('assert'); | ||
| const path = require('path'); | ||
| const fs = require('fs'); | ||
|
|
||
| const tmpdir = require('../common/tmpdir'); | ||
|
|
||
| tmpdir.refresh(); | ||
|
|
||
| const testFileName = 'visible.txt'; | ||
| const testFilePath = path.join(tmpdir.path, testFileName); | ||
| const ignoredFileName = '.hidden'; | ||
| const ignoredFilePath = path.join(tmpdir.path, ignoredFileName); | ||
|
|
||
| const watcher = fs.watch(tmpdir.path, { | ||
| ignore: (filename) => filename.startsWith('.'), | ||
| }); | ||
|
|
||
| watcher.on('change', common.mustCallAtLeast((event, filename) => { | ||
| assert.notStrictEqual(filename, ignoredFileName); | ||
|
|
||
| if (filename === testFileName) { | ||
| watcher.close(); | ||
| } | ||
| }, 1)); | ||
|
|
||
| // Do the write with a delay to ensure that the OS is ready to notify us. See | ||
| // https://github.com/nodejs/node/issues/52601. | ||
| setTimeout(() => { | ||
| fs.writeFileSync(ignoredFilePath, 'ignored'); | ||
| fs.writeFileSync(testFilePath, 'content'); | ||
| }, common.platformTimeout(100)); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| 'use strict'; | ||
|
|
||
| const common = require('../common'); | ||
| const { skipIfNoWatch } = require('../common/watch.js'); | ||
|
|
||
| skipIfNoWatch(); | ||
|
|
||
| // if (common.isSunOS) | ||
| // common.skip('`fs.watch()` is not reliable on SunOS.'); | ||
|
|
||
| const assert = require('assert'); | ||
| const path = require('path'); | ||
| const fs = require('fs'); | ||
|
|
||
| const tmpdir = require('../common/tmpdir'); | ||
|
|
||
| tmpdir.refresh(); | ||
|
|
||
| const testFileName = 'file.txt'; | ||
| const testFilePath = path.join(tmpdir.path, testFileName); | ||
| const ignoredFileName = 'file.log'; | ||
| const ignoredFilePath = path.join(tmpdir.path, ignoredFileName); | ||
|
|
||
| const watcher = fs.watch(tmpdir.path, { | ||
| ignore: '*.log', | ||
| }); | ||
|
|
||
| watcher.on('change', common.mustCallAtLeast((event, filename) => { | ||
| assert.notStrictEqual(filename, ignoredFileName); | ||
|
|
||
| if (filename === testFileName) { | ||
| watcher.close(); | ||
| } | ||
| }, 1)); | ||
|
|
||
| // Do the write with a delay to ensure that the OS is ready to notify us. See | ||
| // https://github.com/nodejs/node/issues/52601. | ||
| setTimeout(() => { | ||
| fs.writeFileSync(ignoredFilePath, 'ignored'); | ||
| fs.writeFileSync(testFilePath, 'content'); | ||
| }, common.platformTimeout(100)); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| 'use strict'; | ||
|
|
||
| require('../common'); | ||
| const { skipIfNoWatch } = require('../common/watch.js'); | ||
|
|
||
| skipIfNoWatch(); | ||
|
|
||
| const assert = require('assert'); | ||
| const fs = require('fs'); | ||
|
|
||
| assert.throws( | ||
| () => fs.watch('.', { ignore: 123 }), | ||
| { | ||
| code: 'ERR_INVALID_ARG_TYPE', | ||
| name: 'TypeError', | ||
| } | ||
| ); | ||
|
|
||
| assert.throws( | ||
| () => fs.watch('.', { ignore: '' }), | ||
| { | ||
| code: 'ERR_INVALID_ARG_VALUE', | ||
| name: 'TypeError', | ||
| } | ||
| ); | ||
|
|
||
| assert.throws( | ||
| () => fs.watch('.', { ignore: [123] }), | ||
| { | ||
| code: 'ERR_INVALID_ARG_TYPE', | ||
| name: 'TypeError', | ||
| } | ||
| ); | ||
|
|
||
| assert.throws( | ||
| () => fs.watch('.', { ignore: [''] }), | ||
| { | ||
| code: 'ERR_INVALID_ARG_VALUE', | ||
| name: 'TypeError', | ||
| } | ||
| ); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| 'use strict'; | ||
|
|
||
| const common = require('../common'); | ||
| const { skipIfNoWatch } = require('../common/watch.js'); | ||
|
|
||
| skipIfNoWatch(); | ||
|
|
||
| // if (common.isSunOS) | ||
| // common.skip('`fs.watch()` is not reliable on SunOS.'); | ||
|
|
||
| const assert = require('assert'); | ||
| const path = require('path'); | ||
| const fs = require('fs'); | ||
|
|
||
| const tmpdir = require('../common/tmpdir'); | ||
|
|
||
| tmpdir.refresh(); | ||
|
|
||
| const testFileName = 'keep.txt'; | ||
| const testFilePath = path.join(tmpdir.path, testFileName); | ||
| const ignoredLogName = 'debug.log'; | ||
| const ignoredLogPath = path.join(tmpdir.path, ignoredLogName); | ||
| const ignoredTmpName = 'temp.tmp'; | ||
| const ignoredTmpPath = path.join(tmpdir.path, ignoredTmpName); | ||
| const ignoredHiddenName = '.secret'; | ||
| const ignoredHiddenPath = path.join(tmpdir.path, ignoredHiddenName); | ||
|
|
||
| const watcher = fs.watch(tmpdir.path, { | ||
| ignore: [ | ||
| '*.log', | ||
| /\.tmp$/, | ||
| (filename) => filename.startsWith('.'), | ||
| ], | ||
| }); | ||
|
|
||
| watcher.on('change', common.mustCallAtLeast((event, filename) => { | ||
| assert.notStrictEqual(filename, ignoredLogName); | ||
| assert.notStrictEqual(filename, ignoredTmpName); | ||
| assert.notStrictEqual(filename, ignoredHiddenName); | ||
|
|
||
| if (filename === testFileName) { | ||
| watcher.close(); | ||
| } | ||
| }, 1)); | ||
|
|
||
| // Do the write with a delay to ensure that the OS is ready to notify us. See | ||
| // https://github.com/nodejs/node/issues/52601. | ||
| setTimeout(() => { | ||
| fs.writeFileSync(ignoredLogPath, 'ignored'); | ||
| fs.writeFileSync(ignoredTmpPath, 'ignored'); | ||
| fs.writeFileSync(ignoredHiddenPath, 'ignored'); | ||
| fs.writeFileSync(testFilePath, 'content'); | ||
| }, common.platformTimeout(100)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These should be replaced with entries in
test/parallel/parallel.statusbut I can't find a tracking issue.