| 1 |
/* eslint max-lines: "off" */ |
| 2 |
|
| 3 |
"use strict"; |
| 4 |
|
| 5 |
const noop = require("es5-ext/function/noop") |
| 6 |
, { resolve } = require("path") |
| 7 |
, isModuleNotFoundError = require("../../is-module-not-found-error"); |
| 8 |
|
| 9 |
const { |
| 10 |
setup: setupFileLinks, |
| 11 |
teardown: teardownFileLinks |
| 12 |
} = require("../_lib/setup-playground-file-symlinks"); |
| 13 |
|
| 14 |
const { |
| 15 |
setup: setupDirLinks, |
| 16 |
teardown: teardownDirLinks |
| 17 |
} = require("../_lib/setup-playground-dir-symlinks"); |
| 18 |
|
| 19 |
const playgroundDir = resolve(__dirname, "../__playground"); |
| 20 |
|
| 21 |
const unexpected = () => { throw new Error("Unexpected"); }; |
| 22 |
|
| 23 |
module.exports = (t, a) => |
| 24 |
Promise.all([ |
| 25 |
t(playgroundDir, "./foo").then(value => { |
| 26 |
a.deep(value, { |
| 27 |
targetPath: resolve(`${ playgroundDir }/foo.js`), |
| 28 |
realPath: resolve(`${ playgroundDir }/foo.js`) |
| 29 |
}); |
| 30 |
}), |
| 31 |
t(playgroundDir, "./foo.js").then(value => { |
| 32 |
a.deep(value, { |
| 33 |
targetPath: resolve(`${ playgroundDir }/foo.js`), |
| 34 |
realPath: resolve(`${ playgroundDir }/foo.js`) |
| 35 |
}); |
| 36 |
}), |
| 37 |
t(playgroundDir, "./foo.json").then(unexpected, error => { |
| 38 |
a(isModuleNotFoundError(error, "./foo.json"), true); |
| 39 |
}), |
| 40 |
t(playgroundDir, "./foo.json", { silent: true }).then(value => a(value, null)), |
| 41 |
t(playgroundDir, "./other").then(value => { |
| 42 |
a.deep(value, { |
| 43 |
targetPath: resolve(`${ playgroundDir }/other.js`), |
| 44 |
realPath: resolve(`${ playgroundDir }/other.js`) |
| 45 |
}); |
| 46 |
}), |
| 47 |
t(playgroundDir, "./other/").then(value => { |
| 48 |
a.deep(value, { |
| 49 |
targetPath: resolve(`${ playgroundDir }/other/index.js`), |
| 50 |
realPath: resolve(`${ playgroundDir }/other/index.js`) |
| 51 |
}); |
| 52 |
}), |
| 53 |
t(playgroundDir, "./samename").then(value => { |
| 54 |
a.deep(value, { |
| 55 |
targetPath: resolve(`${ playgroundDir }/samename`), |
| 56 |
realPath: resolve(`${ playgroundDir }/samename`) |
| 57 |
}); |
| 58 |
}), |
| 59 |
t(playgroundDir, "./samename.js").then(value => { |
| 60 |
a.deep(value, { |
| 61 |
targetPath: resolve(`${ playgroundDir }/samename.js`), |
| 62 |
realPath: resolve(`${ playgroundDir }/samename.js`) |
| 63 |
}); |
| 64 |
}), |
| 65 |
t(playgroundDir, "./samename.json").then(value => { |
| 66 |
a.deep(value, { |
| 67 |
targetPath: resolve(`${ playgroundDir }/samename.json`), |
| 68 |
realPath: resolve(`${ playgroundDir }/samename.json`) |
| 69 |
}); |
| 70 |
}), |
| 71 |
t(playgroundDir, "./samename").then(value => { |
| 72 |
a.deep(value, { |
| 73 |
targetPath: resolve(`${ playgroundDir }/samename`), |
| 74 |
realPath: resolve(`${ playgroundDir }/samename`) |
| 75 |
}); |
| 76 |
}), |
| 77 |
t(playgroundDir, "./dir").then(value => { |
| 78 |
a.deep(value, { |
| 79 |
targetPath: resolve(`${ playgroundDir }/dir/lorem.js`), |
| 80 |
realPath: resolve(`${ playgroundDir }/dir/lorem.js`) |
| 81 |
}); |
| 82 |
}), |
| 83 |
t(playgroundDir, "./dir/lorem").then(value => { |
| 84 |
a.deep(value, { |
| 85 |
targetPath: resolve(`${ playgroundDir }/dir/lorem.js`), |
| 86 |
realPath: resolve(`${ playgroundDir }/dir/lorem.js`) |
| 87 |
}); |
| 88 |
}), |
| 89 |
t(playgroundDir, "./dir/subdir/bar").then(value => { |
| 90 |
a.deep(value, { |
| 91 |
targetPath: resolve(`${ playgroundDir }/dir/subdir/bar.js`), |
| 92 |
realPath: resolve(`${ playgroundDir }/dir/subdir/bar.js`) |
| 93 |
}); |
| 94 |
}), |
| 95 |
t(`${ playgroundDir }/dir`, ".").then(value => { |
| 96 |
a.deep(value, { |
| 97 |
targetPath: resolve(`${ playgroundDir }/dir/lorem.js`), |
| 98 |
realPath: resolve(`${ playgroundDir }/dir/lorem.js`) |
| 99 |
}); |
| 100 |
}), |
| 101 |
t(`${ playgroundDir }/dir`, "./").then(value => { |
| 102 |
a.deep(value, { |
| 103 |
targetPath: resolve(`${ playgroundDir }/dir/lorem.js`), |
| 104 |
realPath: resolve(`${ playgroundDir }/dir/lorem.js`) |
| 105 |
}); |
| 106 |
}), |
| 107 |
t(`${ playgroundDir }/dir`, "./lorem").then(value => { |
| 108 |
a.deep(value, { |
| 109 |
targetPath: resolve(`${ playgroundDir }/dir/lorem.js`), |
| 110 |
realPath: resolve(`${ playgroundDir }/dir/lorem.js`) |
| 111 |
}); |
| 112 |
}), |
| 113 |
t(`${ playgroundDir }/dir`, "../other").then(value => { |
| 114 |
a.deep(value, { |
| 115 |
targetPath: resolve(`${ playgroundDir }/other.js`), |
| 116 |
realPath: resolve(`${ playgroundDir }/other.js`) |
| 117 |
}); |
| 118 |
}), |
| 119 |
t(`${ playgroundDir }/dir`, "../other/").then(value => { |
| 120 |
a.deep(value, { |
| 121 |
targetPath: resolve(`${ playgroundDir }/other/index.js`), |
| 122 |
realPath: resolve(`${ playgroundDir }/other/index.js`) |
| 123 |
}); |
| 124 |
}), |
| 125 |
t(`${ playgroundDir }/dir/subdir`, "../").then(value => { |
| 126 |
a.deep(value, { |
| 127 |
targetPath: resolve(`${ playgroundDir }/dir/lorem.js`), |
| 128 |
realPath: resolve(`${ playgroundDir }/dir/lorem.js`) |
| 129 |
}); |
| 130 |
}), |
| 131 |
t(`${ playgroundDir }/dir/subdir`, "../../foo").then(value => { |
| 132 |
a.deep(value, { |
| 133 |
targetPath: resolve(`${ playgroundDir }/foo.js`), |
| 134 |
realPath: resolve(`${ playgroundDir }/foo.js`) |
| 135 |
}); |
| 136 |
}), |
| 137 |
t(playgroundDir, "outer").then(value => { |
| 138 |
a.deep(value, { |
| 139 |
targetPath: resolve(`${ playgroundDir }/node_modules/outer/raz.js`), |
| 140 |
realPath: resolve(`${ playgroundDir }/node_modules/outer/raz.js`) |
| 141 |
}); |
| 142 |
}), |
| 143 |
t(playgroundDir, "outer/boo").then(value => { |
| 144 |
a.deep(value, { |
| 145 |
targetPath: resolve(`${ playgroundDir }/node_modules/outer/boo.js`), |
| 146 |
realPath: resolve(`${ playgroundDir }/node_modules/outer/boo.js`) |
| 147 |
}); |
| 148 |
}), |
| 149 |
t(playgroundDir, "outer/boo.json").then(unexpected, error => { |
| 150 |
a(isModuleNotFoundError(error, "outer/boo.json"), true); |
| 151 |
}), |
| 152 |
t(playgroundDir, "outer3").then(value => { |
| 153 |
a.deep(value, { |
| 154 |
targetPath: resolve(`${ playgroundDir }/node_modules/outer3/index.js`), |
| 155 |
realPath: resolve(`${ playgroundDir }/node_modules/outer3/index.js`) |
| 156 |
}); |
| 157 |
}), |
| 158 |
t(playgroundDir, "pkg-main-dir").then(value => { |
| 159 |
a.deep(value, { |
| 160 |
targetPath: resolve(`${ playgroundDir }/node_modules/pkg-main-dir/lib/index.js`), |
| 161 |
realPath: resolve(`${ playgroundDir }/node_modules/pkg-main-dir/lib/index.js`) |
| 162 |
}); |
| 163 |
}), |
| 164 |
t(playgroundDir, "nested/elo").then(unexpected, error => { |
| 165 |
a(isModuleNotFoundError(error, "nested/elo"), true); |
| 166 |
}), |
| 167 |
t(playgroundDir, "broken-main").then(value => { |
| 168 |
a.deep(value, { |
| 169 |
targetPath: resolve(`${ playgroundDir }/node_modules/broken-main/index.js`), |
| 170 |
realPath: resolve(`${ playgroundDir }/node_modules/broken-main/index.js`) |
| 171 |
}); |
| 172 |
}), |
| 173 |
t(`${ playgroundDir }/node_modules/outer`, "outer3").then(value => { |
| 174 |
a.deep(value, { |
| 175 |
targetPath: resolve(`${ playgroundDir }/node_modules/outer3/index.js`), |
| 176 |
realPath: resolve(`${ playgroundDir }/node_modules/outer3/index.js`) |
| 177 |
}); |
| 178 |
}), |
| 179 |
t(`${ playgroundDir }/node_modules/outer`, "project/foo").then(unexpected, error => { |
| 180 |
a(isModuleNotFoundError(error, "project/foo"), true); |
| 181 |
}), |
| 182 |
t(`${ playgroundDir }/node_modules/outer`, "nested/elo").then(value => { |
| 183 |
a.deep(value, { |
| 184 |
targetPath: resolve( |
| 185 |
`${ playgroundDir }/node_modules/outer/node_modules/nested/elo.js` |
| 186 |
), |
| 187 |
realPath: resolve( |
| 188 |
`${ playgroundDir }/node_modules/outer/node_modules/nested/elo.js` |
| 189 |
) |
| 190 |
}); |
| 191 |
}), |
| 192 |
t(`${ playgroundDir }/node_modules/outer/node_modules/nested`, "project/foo").then( |
| 193 |
unexpected, |
| 194 |
error => { a(isModuleNotFoundError(error, "project/foo"), true); } |
| 195 |
), |
| 196 |
t(`${ playgroundDir }/node_modules/outer/node_modules/nested`, "outer").then(value => { |
| 197 |
a.deep(value, { |
| 198 |
targetPath: resolve(`${ playgroundDir }/node_modules/outer/raz.js`), |
| 199 |
realPath: resolve(`${ playgroundDir }/node_modules/outer/raz.js`) |
| 200 |
}); |
| 201 |
}), |
| 202 |
t(`${ playgroundDir }/node_modules/outer/node_modules/nested`, "outer/boo").then(value => { |
| 203 |
a.deep(value, { |
| 204 |
targetPath: resolve(`${ playgroundDir }/node_modules/outer/boo.js`), |
| 205 |
realPath: resolve(`${ playgroundDir }/node_modules/outer/boo.js`) |
| 206 |
}); |
| 207 |
}), |
| 208 |
t(`${ playgroundDir }/node_modules/outer/node_modules/nested`, "outer3").then(value => { |
| 209 |
a.deep(value, { |
| 210 |
targetPath: resolve(`${ playgroundDir }/node_modules/outer3/index.js`), |
| 211 |
realPath: resolve(`${ playgroundDir }/node_modules/outer3/index.js`) |
| 212 |
}); |
| 213 |
}), |
| 214 |
|
| 215 |
setupFileLinks().then( |
| 216 |
() => |
| 217 |
Promise.all([ |
| 218 |
t(playgroundDir, "./valid-file-link").then(value => { |
| 219 |
a.deep(value, { |
| 220 |
targetPath: resolve(`${ playgroundDir }/valid-file-link.js`), |
| 221 |
realPath: resolve(`${ playgroundDir }/file-link-target.js`) |
| 222 |
}); |
| 223 |
}), |
| 224 |
t(playgroundDir, "./deep-file-link").then(value => { |
| 225 |
a.deep(value, { |
| 226 |
targetPath: resolve(`${ playgroundDir }/deep-file-link.js`), |
| 227 |
realPath: resolve(`${ playgroundDir }/deep-file-link-target.js`) |
| 228 |
}); |
| 229 |
}), |
| 230 |
t(playgroundDir, "./invalid-file-link").then(unexpected, error => { |
| 231 |
a(isModuleNotFoundError(error, "./invalid-file-link"), true); |
| 232 |
}), |
| 233 |
t(playgroundDir, "./invalid-file-link-with-a-fallback").then(value => { |
| 234 |
a.deep(value, { |
| 235 |
targetPath: resolve( |
| 236 |
`${ playgroundDir }/invalid-file-link-with-a-fallback.json` |
| 237 |
), |
| 238 |
realPath: resolve( |
| 239 |
`${ playgroundDir }/invalid-file-link-with-a-fallback.json` |
| 240 |
) |
| 241 |
}); |
| 242 |
}) |
| 243 |
]).then(teardownFileLinks, error => teardownFileLinks.then(() => { throw error; })), |
| 244 |
error => { |
| 245 |
if (error.code === "EPERM") { |
| 246 |
process.stdout.write( |
| 247 |
"Warning: Could not test file symlinks due to not suffient " + |
| 248 |
"process permissions to create them\n" |
| 249 |
); |
| 250 |
return; |
| 251 |
} |
| 252 |
throw error; |
| 253 |
} |
| 254 |
), |
| 255 |
|
| 256 |
setupDirLinks().then(() => |
| 257 |
Promise.all([ |
| 258 |
t(playgroundDir, "./valid-dir-link").then(value => { |
| 259 |
a.deep(value, { |
| 260 |
targetPath: resolve(`${ playgroundDir }/valid-dir-link/index.js`), |
| 261 |
realPath: resolve(`${ playgroundDir }/dir-link-target/index.js`) |
| 262 |
}); |
| 263 |
}), |
| 264 |
t(playgroundDir, "./deep-dir-link").then(value => { |
| 265 |
a.deep(value, { |
| 266 |
targetPath: resolve(`${ playgroundDir }/deep-dir-link/index.js`), |
| 267 |
realPath: resolve(`${ playgroundDir }/deep-dir-link-target/index.js`) |
| 268 |
}); |
| 269 |
}), |
| 270 |
t(playgroundDir, "./invalid-dir-link").then(unexpected, error => { |
| 271 |
a(isModuleNotFoundError(error, "./invalid-dir-link"), true); |
| 272 |
}) |
| 273 |
]).then(teardownDirLinks, error => teardownDirLinks.then(() => { throw error; })) |
| 274 |
) |
| 275 |
]).then(noop); |