編集

Node.js v22.14.0 (LTS)がリリース

Node.js v22.14.0 (LTS) がリリース。

#globs への exclude オプションの追加

Node.js v22 からサポートされた globglobSync などの API に exclude オプションが追加。

js
import { globSync } from "node:fs";

const files = globSync("**/*.js", {
  exclude: ["**/node_modules/**", "**/dist/**"],
});

#findPackageJSON の追加

近くにある package.json を探す findPackageJSON メソッドが追加。

js
import { findPackageJSON } from "node:module";

findPackageJSON(import.meta.url);
// => /project/package.json

findPackageJSON("some-package", import.meta.url);
// => /project/node_modules/some-package/package.json

#test 関連の API 追加

t.waitFor()t.assert.fileSnapshot()assert.register() などの API が追加。

js
import { assert } from 'node:test';
import { test, assert: testAssert } from 'node:test';

// 独自のassertを登録する
testAssertions.register('isOdd', (n) => {
  assert.strictEqual(n % 2, 1);
});

test('test name', async (t) => {
  //  処理を待機させる
  const result = await t.waitFor(() => {
    return "result";
  }, { timeout: 1000, interval: 1 });

  // ファイルスナップショットを取得
  t.assert.fileSnapshot({ p1: 1, p2: 2 }, './snapshots/snapshot.json');
  t.assert.isOdd(5);
});

#参考文献

編集