From f5e46c9bf2f50d66a953fa133161fc829cecff06 Mon Sep 17 00:00:00 2001 From: Matt Mastracci Date: Sat, 10 Feb 2024 13:22:13 -0700 Subject: chore: move cli/tests/ -> tests/ (#22369) This looks like a massive PR, but it's only a move from cli/tests -> tests, and updates of relative paths for files. This is the first step towards aggregate all of the integration test files under tests/, which will lead to a set of integration tests that can run without the CLI binary being built. While we could leave these tests under `cli`, it would require us to keep a more complex directory structure for the various test runners. In addition, we have a lot of complexity to ignore various test files in the `cli` project itself (cargo publish exclusion rules, autotests = false, etc). And finally, the `tests/` folder will eventually house the `test_ffi`, `test_napi` and other testing code, reducing the size of the root repo directory. For easier review, the extremely large and noisy "move" is in the first commit (with no changes -- just a move), while the remainder of the changes to actual files is in the second commit. --- .../node_compat/test/parallel/test-fs-watchfile.js | 112 --------------------- 1 file changed, 112 deletions(-) delete mode 100644 cli/tests/node_compat/test/parallel/test-fs-watchfile.js (limited to 'cli/tests/node_compat/test/parallel/test-fs-watchfile.js') diff --git a/cli/tests/node_compat/test/parallel/test-fs-watchfile.js b/cli/tests/node_compat/test/parallel/test-fs-watchfile.js deleted file mode 100644 index 3a77fb56d..000000000 --- a/cli/tests/node_compat/test/parallel/test-fs-watchfile.js +++ /dev/null @@ -1,112 +0,0 @@ -// deno-fmt-ignore-file -// deno-lint-ignore-file - -// Copyright Joyent and Node contributors. All rights reserved. MIT license. -// Taken from Node 18.12.1 -// This file is automatically generated by `tools/node_compat/setup.ts`. Do not modify this file manually. - -'use strict'; -const common = require('../common'); - -const assert = require('assert'); -const fs = require('fs'); -const path = require('path'); - -const tmpdir = require('../common/tmpdir'); - -// Basic usage tests. -assert.throws( - () => { - fs.watchFile('./some-file'); - }, - { - code: 'ERR_INVALID_ARG_TYPE', - name: 'TypeError' - }); - -assert.throws( - () => { - fs.watchFile('./another-file', {}, 'bad listener'); - }, - { - code: 'ERR_INVALID_ARG_TYPE', - name: 'TypeError' - }); - -assert.throws(() => { - fs.watchFile(new Object(), common.mustNotCall()); -}, { code: 'ERR_INVALID_ARG_TYPE', name: 'TypeError' }); - -const enoentFile = path.join(tmpdir.path, 'non-existent-file'); -const expectedStatObject = new fs.Stats( - 0, // dev - 0, // mode - 0, // nlink - 0, // uid - 0, // gid - 0, // rdev - 0, // blksize - 0, // ino - 0, // size - 0, // blocks - Date.UTC(1970, 0, 1, 0, 0, 0), // atime - Date.UTC(1970, 0, 1, 0, 0, 0), // mtime - Date.UTC(1970, 0, 1, 0, 0, 0), // ctime - Date.UTC(1970, 0, 1, 0, 0, 0) // birthtime -); - -tmpdir.refresh(); - -// If the file initially didn't exist, and gets created at a later point of -// time, the callback should be invoked again with proper values in stat object -let fileExists = false; - -const watcher = - fs.watchFile(enoentFile, { interval: 0 }, common.mustCall((curr, prev) => { - if (!fileExists) { - // If the file does not exist, all the fields should be zero and the date - // fields should be UNIX EPOCH time - assert.deepStrictEqual(curr, expectedStatObject); - assert.deepStrictEqual(prev, expectedStatObject); - // Create the file now, so that the callback will be called back once the - // event loop notices it. - fs.closeSync(fs.openSync(enoentFile, 'w')); - fileExists = true; - } else { - // If the ino (inode) value is greater than zero, it means that the file - // is present in the filesystem and it has a valid inode number. - assert(curr.ino > 0); - // As the file just got created, previous ino value should be lesser than - // or equal to zero (non-existent file). - assert(prev.ino <= 0); - // Stop watching the file - fs.unwatchFile(enoentFile); - watcher.stop(); // Stopping a stopped watcher should be a noop - } - }, 2)); - -// 'stop' should only be emitted once - stopping a stopped watcher should -// not trigger a 'stop' event. -watcher.on('stop', common.mustCall()); - -// Watch events should callback with a filename on supported systems. -// Omitting AIX. It works but not reliably. -if (common.isLinux || common.isOSX || common.isWindows) { - const dir = path.join(tmpdir.path, 'watch'); - - fs.mkdir(dir, common.mustCall(function(err) { - if (err) assert.fail(err); - - fs.watch(dir, common.mustCall(function(eventType, filename) { - clearInterval(interval); - this._handle.close(); - assert.strictEqual(filename, 'foo.txt'); - })); - - const interval = setInterval(() => { - fs.writeFile(path.join(dir, 'foo.txt'), 'foo', common.mustCall((err) => { - if (err) assert.fail(err); - })); - }, 1); - })); -} -- cgit v1.2.3