Remove mockfs use memfs#1574
Closed
ShinobuTakahashi wants to merge 7 commits intoremove-browserify-use-rollupfrom
Closed
Remove mockfs use memfs#1574ShinobuTakahashi wants to merge 7 commits intoremove-browserify-use-rollupfrom
ShinobuTakahashi wants to merge 7 commits intoremove-browserify-use-rollupfrom
Conversation
| mockfs(mockFsContent); | ||
|
|
||
| let pkgjsonPaths = await NodeModules.listModuleFiles(".", ["dummy@1", "dummy2", "dummy3"], logger); | ||
| let pkgjsonPaths = await NodeModules.listModuleFiles(contentPath, ["dummy", "dummy2", "dummy3"], logger); |
Contributor
Author
There was a problem hiding this comment.
dummy@1 という名前がそもそもないので rollup で not found でエラーとなるので dummy に修正
xnv
reviewed
Jul 29, 2025
| import { Util } from ".."; | ||
|
|
||
| describe("NodeModules", () => { | ||
| const mockFsContent = { |
Member
There was a problem hiding this comment.
うーん、実ファイルを展開するしかないという話をしたのは私で申し訳ないんですが、こうして見ると「相互依存度の高い」「(テスト用なので) 名前を見ても大して中身がわからない」「1-2行の」ファイル (=テストコードとセットで見ないと意味がないファイル) が量産されてつらいことになってしまいますね……。特にファイルが多いほかのモジュールでもやると大変そうです。
ちょっと方針転換して、この mock 定義をそのまま実ファイルシステムに展開するユーティリティを作る路線はどうでしょうか。
イメージ:
interface FSContentDescDir {
[filename: string]: FSContentDescDir | string;
}
function setupFsContentImpl(baseDir: string, key: string, def: FSContentDescDir): void {
if (typeof def === "string") {
if (def.startsWith("simlink:")) {
...
} else {
...
}
} else {
const dir = join(baseDir, key)
mkdir(dir);
setupFsContent(dir, def);
}
}
function setupFsContent(baseDir: string, def: FSContentDescDir): void {
Object.entries(def).forEach(([key, val] => {
setupFsContentImpl(baseDir, key, val);
});
}
export function withFsContent<T>(def: FSContentDescDir, fun: () => Promise<T>): Promise<T> {
const dir = mkdtemp();
setupFsContent(dir, def);
try {
return await fun();
} finally {
rm(dir, { recursive: true, force: true });
}
}
Member
There was a problem hiding this comment.
議論: withFsContent のように実行までラップするより、vol.fromJSON() と同じ形 (vol.reset() 的な関数を afterEach() で呼ぶ) 方がほかテストと形が揃っていてわかりやすいかも。
Contributor
Author
There was a problem hiding this comment.
ありがとうございます。この PR をクローズし別途 PR を作成します。
Contributor
Author
|
実ファイルシステムを展開するユーティリティで対応するためこの PR をクローズします。 |
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
概要
#1561 の browserify -> rollup 変更に伴うテスト周りの修正。
mock-fsをmemfsへ変更。備考
#1561 へマージします。commons 以外の対応が完了しCIが通るまでマージしません
scan と lib-manage で一部 commons の NodeModules.ts を利用している箇所でテストが落ちている。別途対応。