From cbbae7f8b474b0b3e3ffbf4c39052950bc930c64 Mon Sep 17 00:00:00 2001 From: Laurence de Bruxelles Date: Tue, 17 May 2022 10:16:43 +0100 Subject: [PATCH] Fix Sass compilation in tests There is a bug where `sass.compile` will throw with an extremely unhelpful error trace when running in Jest [[1]]. > TypeError: J.getInterceptor$ax(...).map$1$1 is not a function > > at Object.map$1$1$ax (node_modules/sass/sass.dart.js:24513:44) > at listDir_closure0.call$0 (node_modules/sass/sass.dart.js:87066:18) > at Object._systemErrorToFileSystemException0 (node_modules/sass/sass.dart.js:20776:23) > at Object.listDir0 (node_modules/sass/sass.dart.js:20771:16) > at _realCasePath_helper_closure0.call$0 (node_modules/sass/sass.dart.js:84710:34) > at JsLinkedHashMap.putIfAbsent$2 (node_modules/sass/sass.dart.js:27273:24) > at _realCasePath_helper0.call$1 (node_modules/sass/sass.dart.js:84699:32) > at _realCasePath_helper_closure0.call$0 (node_modules/sass/sass.dart.js:84706:35) > at JsLinkedHashMap.putIfAbsent$2 (node_modules/sass/sass.dart.js:27273:24) > at _realCasePath_helper0.call$1 (node_modules/sass/sass.dart.js:84699:32) It has been suggested that it is related to `path.absolute` being overridden by the jsdom environment [[2]], but the workaround of using the "node" environment does not solve the issue for us. Instead, what did work is using the legacy API [[3]]. I'm not sure why this is, but it seems to do the trick. Note that with the legacy API, the file path is part of the options object, rather than being the first argument. If you forget to change the call signature, you will get a different unhelpful error message: > NoSuchMethodError: method not found: 'call' [1]: https://github.com/sass/dart-sass/issues/1692 [2]: https://github.com/sass/dart-sass/issues/710#issuecomment-704227380 [3]: https://sass-lang.com/documentation/js-api#legacy-api --- build/run-tasks.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/build/run-tasks.js b/build/run-tasks.js index 31f08d3ee7..a9e303d1e9 100644 --- a/build/run-tasks.js +++ b/build/run-tasks.js @@ -47,7 +47,8 @@ function sass (sassPath, cssPath) { if (!file.endsWith('.scss')) return try { - const result = sass.compile(`${sassPath}/${file}`, { + const result = sass.renderSync({ + file: `${sassPath}/${file}`, logger: sass.Logger.silent, loadPaths: [__dirname], sourceMap: true,