Use memfs other#1586
Conversation
| export function prepareFsContent(def: FsContentDefinition, baseDir: string): PrepareFsContentResult { | ||
| const dir = fs.mkdtempSync(baseDir); | ||
| export function prepareFsContent(def: FsContentDefinition, baseDir: string, useDirPath?: string): PrepareFsContentResult { | ||
| const dir = useDirPath ? useDirPath : fs.mkdtempSync(baseDir); |
There was a problem hiding this comment.
テストで同ディレクトリに対しファイルの追加があるため、引数 useDirPath があった場合にはそのディレクトリパスを使用するようにしました。
There was a problem hiding this comment.
うーん、第二第三引数はほとんど意味が重複しているのは抵抗があります。mkdtemp() を呼び出し元の責任にしませんか。
通常:
prepareFsContent(def, fs.mkdtempSync(baseDir));今回必要なパス:
prepareFsContent(def, path.join(fixtureContents.path, "somedir", "node_modules"));There was a problem hiding this comment.
ありがとうございます。mkdtemp() を呼び出し元の責務にするよう修正しました。
| .then(() => promiseInstall({ moduleNames: ["dummy2@1.0.1"], cwd: "./somedir", plugin: 12, logger: logger, debugNpm: dummyNpm })) | ||
| .then(() => cmn.FileSystem.readJSON<cmn.GameConfiguration>("./somedir/game.json")) | ||
| .then(() => promiseInstall({ moduleNames: ["dummy2"], cwd: somedir, plugin: 12, logger: logger, debugNpm: dummyNpm })) | ||
| .then(() => cmn.FileSystem.readJSON<cmn.GameConfiguration>(path.join(somedir, "game.json"))) |
There was a problem hiding this comment.
モジュール名の "@x.x.x" は rollup で解決できないため削除
There was a problem hiding this comment.
バージョンを指定しての akashic install ができなくなるということでしょうか?
There was a problem hiding this comment.
moduleName@x.x.x で install できるよう修正しました。
| const moduleMainScripts = NodeModules.listModuleMainScripts(packageJsonFiles); | ||
|
|
||
| // CI の windows 用にファイルパスを unix 形式に変換して比較 | ||
| for(const [key, value] of Object.entries(moduleMainScripts)) moduleMainScripts[key] = toUnixPath(value); |
There was a problem hiding this comment.
listModuleMainScripts() の戻り値 (game.json にそのまま書く) は常に unix path ではないかと思いますが、この処理必要でしょうか?
There was a problem hiding this comment.
仰る通りです。この処理削除しました。
| const moduleMainPaths = NodeModules.listModuleMainPaths(packageJsonFiles); | ||
|
|
||
| // CI の windows 用にファイルパスを unix 形式に変換して比較 | ||
| for(const [key, value] of Object.entries(moduleMainPaths)) moduleMainPaths[key] = toUnixPath(value); |
| export function prepareFsContent(def: FsContentDefinition, baseDir: string): PrepareFsContentResult { | ||
| const dir = fs.mkdtempSync(baseDir); | ||
| export function prepareFsContent(def: FsContentDefinition, baseDir: string, useDirPath?: string): PrepareFsContentResult { | ||
| const dir = useDirPath ? useDirPath : fs.mkdtempSync(baseDir); |
There was a problem hiding this comment.
うーん、第二第三引数はほとんど意味が重複しているのは抵抗があります。mkdtemp() を呼び出し元の責任にしませんか。
通常:
prepareFsContent(def, fs.mkdtempSync(baseDir));今回必要なパス:
prepareFsContent(def, path.join(fixtureContents.path, "somedir", "node_modules"));| const mockFsContent = { | ||
| "source": { |
There was a problem hiding this comment.
ありがとうございます。修正しました。
| const rmPath = path.join(fixtureContents.path, "testdir", "foo", "node_modules", name); | ||
| fs.rmSync(rmPath, {recursive: true}); |
There was a problem hiding this comment.
DummyNpm は実ファイルを触らずに npm の動作を模擬するものだったように見えるのですが、ここで実ファイルを削除する必要があるんでしょうか。(だとするとこれまでなぜ動いていたのか不思議なような?)
There was a problem hiding this comment.
仰る通り、ここで実ファイルを削除せずとも問題ありませんでした。修正しました。
| .then(() => promiseInstall({ moduleNames: ["dummy2@1.0.1"], cwd: "./somedir", plugin: 12, logger: logger, debugNpm: dummyNpm })) | ||
| .then(() => cmn.FileSystem.readJSON<cmn.GameConfiguration>("./somedir/game.json")) | ||
| .then(() => promiseInstall({ moduleNames: ["dummy2"], cwd: somedir, plugin: 12, logger: logger, debugNpm: dummyNpm })) | ||
| .then(() => cmn.FileSystem.readJSON<cmn.GameConfiguration>(path.join(somedir, "game.json"))) |
There was a problem hiding this comment.
バージョンを指定しての akashic install ができなくなるということでしょうか?
| .then(async () => { | ||
| const ret = await cmn.FileSystem.readJSON<cmn.GameConfiguration>(path.join(somedir, "game.json")) | ||
| return ret; | ||
| }) |
There was a problem hiding this comment.
Promise 返すだけなので async も await も変数もいらなくてこれでいいような?
.then(() => cmn.FileSystem.readJSON<cmn.GameConfiguration>(path.join(somedir, "game.json")))There was a problem hiding this comment.
デバッグ時に確認のため修正したままでした。await 等削除し戻しました。
| import { readJSON, writeJSON } from "@akashic/akashic-cli-commons/lib/FileSystem.js"; | ||
|
|
||
| vi.mock("node:fs", async () => { | ||
| const memfs: { fs: typeof fs } = await vi.importActual("memfs") |
There was a problem hiding this comment.
ありがとうございます。修正しました。
| import { Util } from ".."; | ||
| import * as testUtil from "./helpers/TestUtil.js"; | ||
|
|
||
| const toUnixPath = (p: string) => p.replace(/^\//, "").replace(/\\/g, "/"); |
There was a problem hiding this comment.
0 文字目の "/" を削るのは toUnixPath() という名前にそぐわないので、 toGameJsonPath() とかにしておくのはどうでしょう。
There was a problem hiding this comment.
ありがとうございます。toGameJsonPath() へ修正しました。
| expect(content.moduleMainScripts).toEqual({ | ||
| "dummy": "node_modules/dummy/index2.js", | ||
| "dummyChild": "node_modules/dummy/node_modules/dummyChild/main.js" | ||
| }); |
There was a problem hiding this comment.
コメントアウトした箇所の影響で、dummy モジュールは初回インストールした内容のため修正しました。
| expect(globalScripts.indexOf("node_modules/dummy/foo.js")).toBe(-1); | ||
| expect(globalScripts.indexOf("node_modules/dummy/node_modules/dummyChild/main.js")).toBe(-1); | ||
| expect(globalScripts.indexOf("node_modules/dummy/index2.js")).not.toBe(-1); | ||
| expect(globalScripts.indexOf("node_modules/dummy/sub2.js")).not.toBe(-1); |
There was a problem hiding this comment.
このあたりもばっさり削られていますが、そうすると上の // dummyモジュールの定義を書き換えて反映されるか確認する の部分の意味がなくなっていませんか。もしこのあたりをテストする意味がないなら書き換え部分も削除されるべきに思えます。
There was a problem hiding this comment.
別途ご相談させてきただき、rollup で変更したpackage.json が認識できないため、このブロックをコメントアウトとしました。
| }) | ||
| /* | ||
| // Rollup は一度読み込んだ package.json が変更された場合、packag.json の main フィールドが変わっても検知できない。 | ||
| // そのため、下記の dummy モジュールの中身が変更されて反映できているかのブロックをコメントアウトとする。 |
There was a problem hiding this comment.
厳密には --watch 中に node_modules 以下の package.json 書き換えを検知できなくなっているので、デグレである。ただ回避手段が見当たらないこと、現実的にほぼないユースケースであるため妥協する という点も書いておきたいです。
There was a problem hiding this comment.
ありがとうございます。コメント追加しました。
概要
#1561 の browserify -> rollup 変更に伴うテスト周りの修正。
備考
#1576 へマージします。この PR で CI が通る事を確認。
ローカルでテスト後に実ファイルが残らない事を確認。