* @param {string} testId test fixture identifier * @param {EXPECTED_ANY=} options options * @param {EXPECTED_ANY=} context test context * @returns {Promise<{ css: string, map: EXPECTED_ANY }>} stylus result
(testId, options = {}, context = {})
| 153 | * @returns {Promise<{ css: string, map: EXPECTED_ANY }>} stylus result |
| 154 | */ |
| 155 | async function getCodeFromStylus(testId, options = {}, context = {}) { |
| 156 | const defaultOptions = { |
| 157 | shouldUseWebpackImporter: true, |
| 158 | }; |
| 159 | const stylusOptions = options.stylusOptions || {}; |
| 160 | |
| 161 | let pathToFile; |
| 162 | |
| 163 | if (context.packageExportsCustomConditionTestVariant === 1) { |
| 164 | pathToFile = path.resolve( |
| 165 | __dirname, |
| 166 | "..", |
| 167 | "fixtures", |
| 168 | "node_modules/package-with-exports-and-custom-condition/style-1.styl", |
| 169 | ); |
| 170 | } else if (context.packageExportsCustomConditionTestVariant === 2) { |
| 171 | pathToFile = path.resolve( |
| 172 | __dirname, |
| 173 | "..", |
| 174 | "fixtures", |
| 175 | "node_modules/package-with-exports-and-custom-condition/style-2.styl", |
| 176 | ); |
| 177 | } else { |
| 178 | pathToFile = path.resolve(__dirname, "..", "fixtures", testId); |
| 179 | } |
| 180 | |
| 181 | let data; |
| 182 | |
| 183 | try { |
| 184 | data = await fs.promises.readFile(pathToFile); |
| 185 | // May be directory |
| 186 | } catch (err) { |
| 187 | pathToFile = path.resolve(pathToFile, "index.styl"); |
| 188 | |
| 189 | data = await fs.promises.readFile(pathToFile); |
| 190 | |
| 191 | if (typeof data === "undefined") { |
| 192 | throw err; |
| 193 | } |
| 194 | } |
| 195 | |
| 196 | if (typeof options.additionalData !== "undefined") { |
| 197 | data = |
| 198 | typeof options.additionalData === "function" |
| 199 | ? `${options.additionalData(data, { |
| 200 | rootContext: path.resolve(__dirname, "../fixtures"), |
| 201 | resourcePath: pathToFile, |
| 202 | })}` |
| 203 | : `${options.additionalData}\n${data}`; |
| 204 | } |
| 205 | |
| 206 | const mergedOptions = { |
| 207 | ...defaultOptions, |
| 208 | ...stylusOptions, |
| 209 | }; |
| 210 | |
| 211 | mergedOptions.filename = pathToFile; |
| 212 | mergedOptions.dest = path.dirname(pathToFile); |
no test coverage detected
searching dependent graphs…