diff options
author | 2024-10-15 15:34:42 +0800 | |
---|---|---|
committer | 2024-10-15 15:34:42 +0800 | |
commit | 64bb796c0fee551b8b2349b5246946f60080565b (patch) | |
tree | 6caff13adaa98b6cb46901a433f332a25da4ee63 /patches/fs-fixture@2.4.0.patch | |
parent | 5ab2d980aae8c92e71e01a8bd21c8d771e576085 (diff) | |
download | astro-64bb796c0fee551b8b2349b5246946f60080565b.tar.gz astro-64bb796c0fee551b8b2349b5246946f60080565b.tar.zst astro-64bb796c0fee551b8b2349b5246946f60080565b.zip |
Use real filesystem for unit testing (#12172)
Diffstat (limited to 'patches/fs-fixture@2.4.0.patch')
-rw-r--r-- | patches/fs-fixture@2.4.0.patch | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/patches/fs-fixture@2.4.0.patch b/patches/fs-fixture@2.4.0.patch new file mode 100644 index 000000000..1ec3a3c4d --- /dev/null +++ b/patches/fs-fixture@2.4.0.patch @@ -0,0 +1,24 @@ +diff --git a/dist/index.d.mts b/dist/index.d.mts +index be5b88e034211892ba079c3c5c5c6f5d5f767cd4..55dcc0e99c66719d5fa68d4713b02c1919deae19 100644 +--- a/dist/index.d.mts ++++ b/dist/index.d.mts +@@ -61,6 +61,10 @@ type Api = ApiBase & { + type FileTree = { + [path: string]: string | FileTree | ((api: Api) => string | Symlink); + }; +-declare const createFixture: (source?: string | FileTree) => Promise<FsFixture>; ++type CreateFixtureOptions = { ++ // An absolute path to a different directory than `os.tmpdir()` ++ tempDir?: string ++} ++declare const createFixture: (source?: string | FileTree, opts?: CreateFixtureOptions) => Promise<FsFixture>; + +-export { type FileTree, FsFixture, createFixture }; ++export { type FileTree, FsFixture, CreateFixtureOptions, createFixture }; +diff --git a/dist/index.mjs b/dist/index.mjs +index cd6cab3beebf3f38fe4f1e2a9c58aff2b87258f7..ad24d852a357fd582f9e83ac20cb73bfbcb9bfc0 100755 +--- a/dist/index.mjs ++++ b/dist/index.mjs +@@ -1 +1 @@ +-import s from"fs/promises";import o from"path";import y from"fs";import m from"os";typeof Symbol.asyncDispose!="symbol"&&Object.defineProperty(Symbol,"asyncDispose",{configurable:!1,enumerable:!1,writable:!1,value:Symbol.for("asyncDispose")});class w{path;constructor(t){this.path=t}getPath(...t){return o.join(this.path,...t)}exists(t=""){return s.access(this.getPath(t)).then(()=>!0,()=>!1)}rm(t=""){return s.rm(this.getPath(t),{recursive:!0,force:!0})}writeFile(t,r){return s.writeFile(this.getPath(t),r)}writeJson(t,r){return this.writeFile(t,JSON.stringify(r,null,2))}readFile(t,r){return s.readFile(this.getPath(t),r)}async[Symbol.asyncDispose](){await this.rm()}}const g=y.realpathSync(m.tmpdir()),b=`fs-fixture-${Date.now()}`;let l=0;const P=()=>(l+=1,l);class h{target;type;path;constructor(t,r){this.target=t,this.type=r}}const u=(i,t,r)=>{const e=[];for(const n in i){if(!Object.hasOwn(i,n))continue;const c=o.join(t,n);let a=i[n];if(typeof a=="function"){const f=Object.assign(Object.create(r),{filePath:c}),p=a(f);if(p instanceof h){p.path=c,e.push(p);continue}else a=p}typeof a=="string"?e.push({path:c,content:a}):e.push(...u(a,c,r))}return e},d=async i=>{const t=o.join(g,`${b}-${P()}/`);if(await s.mkdir(t,{recursive:!0}),i){if(typeof i=="string")await s.cp(i,t,{recursive:!0});else if(typeof i=="object"){const r={fixturePath:t,getPath:(...e)=>o.join(t,...e),symlink:(e,n)=>new h(e,n)};await Promise.all(u(i,t,r).map(async e=>{await s.mkdir(o.dirname(e.path),{recursive:!0}),e instanceof h?await s.symlink(e.target,e.path,e.type):await s.writeFile(e.path,e.content)}))}}return new w(t)};export{d as createFixture}; ++import s from"fs/promises";import o from"path";import y from"fs";import m from"os";typeof Symbol.asyncDispose!="symbol"&&Object.defineProperty(Symbol,"asyncDispose",{configurable:!1,enumerable:!1,writable:!1,value:Symbol.for("asyncDispose")});class w{path;constructor(t){this.path=t}getPath(...t){return o.join(this.path,...t)}exists(t=""){return s.access(this.getPath(t)).then(()=>!0,()=>!1)}rm(t=""){return s.rm(this.getPath(t),{recursive:!0,force:!0})}writeFile(t,r){return s.writeFile(this.getPath(t),r)}writeJson(t,r){return this.writeFile(t,JSON.stringify(r,null,2))}readFile(t,r){return s.readFile(this.getPath(t),r)}async[Symbol.asyncDispose](){await this.rm()}}const g=y.realpathSync(m.tmpdir()),b=`fs-fixture-${Date.now()}`;let l=0;const P=()=>(l+=1,l);class h{target;type;path;constructor(t,r){this.target=t,this.type=r}}const u=(i,t,r)=>{const e=[];for(const n in i){if(!Object.hasOwn(i,n))continue;const c=o.join(t,n);let a=i[n];if(typeof a=="function"){const f=Object.assign(Object.create(r),{filePath:c}),p=a(f);if(p instanceof h){p.path=c,e.push(p);continue}else a=p}typeof a=="string"?e.push({path:c,content:a}):e.push(...u(a,c,r))}return e},d=async (i, opts)=>{const t=o.join(opts?.tempDir ?? g,`${b}-${P()}/`);if(await s.mkdir(t,{recursive:!0}),i){if(typeof i=="string")await s.cp(i,t,{recursive:!0});else if(typeof i=="object"){const r={fixturePath:t,getPath:(...e)=>o.join(t,...e),symlink:(e,n)=>new h(e,n)};await Promise.all(u(i,t,r).map(async e=>{await s.mkdir(o.dirname(e.path),{recursive:!0}),e instanceof h?await s.symlink(e.target,e.path,e.type):await s.writeFile(e.path,e.content)}))}}return new w(t)};export{d as createFixture}; |