Index: test/stub-modules/io.js |
=================================================================== |
--- a/test/stub-modules/io.js |
+++ b/test/stub-modules/io.js |
@@ -25,74 +25,62 @@ |
}, |
_setModifiedTime(fileName, lastModified) |
{ |
if (data.has(fileName)) |
data.get(fileName).lastModified = lastModified; |
}, |
// Public API |
- writeToFile(fileName, generator) |
+ async writeToFile(fileName, generator) |
{ |
- return Promise.resolve().then(() => |
- { |
- data.set(fileName, { |
- lastModified: Date.now(), |
- contents: Array.from(generator) |
- }); |
- }); |
- }, |
- readFromFile(fileName, listener) |
- { |
- return Promise.resolve().then(() => |
- { |
- if (!data.has(fileName)) |
- throw new Error("File doesn't exist"); |
- |
- let lines = data.get(fileName).contents; |
- for (let line of lines) |
- listener(line); |
+ data.set(fileName, { |
+ lastModified: Date.now(), |
+ contents: Array.from(generator) |
}); |
}, |
- copyFile(fromName, toName) |
+ async readFromFile(fileName, listener) |
{ |
- return Promise.resolve().then(() => |
- { |
- if (!data.has(fromName)) |
- throw new Error("File doesn't exist"); |
- if (fromName == toName) |
- throw new Error("Cannot copy file to itself"); |
+ if (!data.has(fileName)) |
+ throw new Error("File doesn't exist"); |
+ |
+ let lines = data.get(fileName).contents; |
+ for (let line of lines) |
+ listener(line); |
+ }, |
+ async copyFile(fromName, toName) |
+ { |
+ if (!data.has(fromName)) |
+ throw new Error("File doesn't exist"); |
+ |
+ if (fromName == toName) |
+ throw new Error("Cannot copy file to itself"); |
- data.set(toName, data.get(fromName)); |
- }); |
+ data.set(toName, data.get(fromName)); |
}, |
- renameFile(fromName, toName) |
+ async renameFile(fromName, toName) |
+ { |
+ await this.copyFile(fromName, toName); |
+ await this.removeFile(fromName); |
Manish Jethani
2019/01/17 09:29:55
Note that to be exactly like the previous version
|
+ }, |
+ async removeFile(fileName) |
{ |
- return this.copyFile(fromName, toName).then(() => this.removeFile(fromName)); |
+ if (!data.has(fileName)) |
+ throw new Error("File doesn't exist"); |
+ |
+ data.delete(fileName); |
}, |
- removeFile(fileName) |
+ async statFile(fileName) |
{ |
- return Promise.resolve().then(() => |
+ if (data.has(fileName)) |
{ |
- if (!data.has(fileName)) |
- throw new Error("File doesn't exist"); |
+ return { |
+ exists: true, |
+ lastModified: data.get(fileName).lastModified |
+ }; |
+ } |
- data.delete(fileName); |
- }); |
- }, |
- statFile(fileName) |
- { |
- return Promise.resolve().then(() => |
- { |
- if (data.has(fileName)) |
- { |
- return { |
- exists: true, |
- lastModified: data.get(fileName).lastModified |
- }; |
- } |
- return { |
- exists: false, |
- lastModified: 0 |
- }; |
- }); |
+ return { |
+ exists: false, |
+ lastModified: 0 |
+ }; |
} |
}; |