(testName: string, test: (module: any) => void)
| 113 | } |
| 114 | |
| 115 | function generateEmscriptenTest(testName: string, test: (module: any) => void) { |
| 116 | // Only applicable to typed array-compatible browsers. |
| 117 | if (typeof(Uint8Array) !== 'undefined') { |
| 118 | it(`[Emscripten] Initialize FileSystem`, () => { |
| 119 | BrowserFS.initialize(new BrowserFS.FileSystem.InMemory()); |
| 120 | }); |
| 121 | generateTest(`[Emscripten] Load fixtures (${testName})`, loadFixtures); |
| 122 | it(`[Emscripten] ${testName}`, function(done: (e?: any) => void) { |
| 123 | let stdout = ""; |
| 124 | let stderr = ""; |
| 125 | let expectedStdout: string = null; |
| 126 | let expectedStderr: string = null; |
| 127 | let testNameNoExt = testName.slice(0, testName.length - path.extname(testName).length); |
| 128 | try { |
| 129 | expectedStdout = fs.readFileSync(`/test/fixtures/files/emscripten/${testNameNoExt}.out`).toString().replace(/\r/g, ''); |
| 130 | expectedStderr = fs.readFileSync(`/test/fixtures/files/emscripten/${testNameNoExt}.err`).toString().replace(/\r/g, ''); |
| 131 | } catch (e) { |
| 132 | // No stdout/stderr test. |
| 133 | } |
| 134 | |
| 135 | const Module = { |
| 136 | // Explicitly override arguments, since newer Emscripten versions |
| 137 | // will incorrectly default it to the arguments object passed to |
| 138 | // the module we enclose the program in, and then try to coerce |
| 139 | // everything into a string (bad) |
| 140 | arguments: <string[]> [], |
| 141 | print: function(text: string) { stdout += text + '\n'; }, |
| 142 | printErr: function(text: string) { stderr += text + '\n'; }, |
| 143 | onExit: function(code: number) { |
| 144 | if (code !== 0) { |
| 145 | done(new Error(`Program exited with code ${code}.\nstdout:\n${stdout}\nstderr:\n${stderr}`)); |
| 146 | } else { |
| 147 | if (expectedStdout !== null) { |
| 148 | assert.equal(stdout.trim(), expectedStdout.trim()); |
| 149 | assert.equal(stderr.trim(), expectedStderr.trim()); |
| 150 | } |
| 151 | done(); |
| 152 | } |
| 153 | }, |
| 154 | // Block standard input. Otherwise, the unit tests inexplicably read from stdin??? |
| 155 | stdin: function(): any { |
| 156 | return null; |
| 157 | }, |
| 158 | locateFile: function(fname: string): string { |
| 159 | return `/test/tests/emscripten/${fname}`; |
| 160 | }, |
| 161 | preRun: function() { |
| 162 | const FS = Module.FS; |
| 163 | const BFS = new BFSEmscriptenFS(FS, Module.PATH, Module.ERRNO_CODES); |
| 164 | FS.mkdir('/files'); |
| 165 | // console.log(BrowserFS.BFSRequire('fs').readdirSync('/test/fixtures/files/emscripten')); |
| 166 | FS.mount(BFS, {root: '/test/fixtures/files/emscripten'}, '/files'); |
| 167 | FS.chdir('/files'); |
| 168 | }, |
| 169 | ENVIRONMENT: "WEB", |
| 170 | FS: <any> undefined, |
| 171 | PATH: <any> undefined, |
| 172 | ERRNO_CODES: <any> undefined |
no test coverage detected