From b0eec86e50f3b5fae410ff367c5e56513ebc1bff 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 --- run-tasks.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/run-tasks.js b/run-tasks.js index 9646e84dc2..a859f12fd7 100644 --- a/run-tasks.js +++ b/run-tasks.js @@ -43,7 +43,8 @@ function sass () { fs.readdirSync('app/assets/sass').forEach(file => { if (!file.endsWith('.scss')) return - const result = sass.compile('app/assets/sass/' + file, { + const result = sass.renderSync({ + file: 'app/assets/sass/' + file, logger: sass.Logger.silent, loadPaths: [__dirname], sourceMap: true,