From 2c54b54a8736dc9c383d1f1bbdcb117490e46139 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Granstr=C3=B6m?= Date: Sat, 4 Nov 2023 18:17:26 +0100 Subject: [PATCH] fix: map tests for incompatible node-sass syntax --- test/helpers/implementation_iterator.js | 2 +- test/map-keys.js | 33 ++++++++++++------- ...{map-keys.scss => map-keys_dart-sass.scss} | 2 +- test/sass/map-keys_node-sass.scss | 24 ++++++++++++++ 4 files changed, 47 insertions(+), 14 deletions(-) rename test/sass/{map-keys.scss => map-keys_dart-sass.scss} (74%) create mode 100644 test/sass/map-keys_node-sass.scss diff --git a/test/helpers/implementation_iterator.js b/test/helpers/implementation_iterator.js index b44e1ed..ab7a7e6 100644 --- a/test/helpers/implementation_iterator.js +++ b/test/helpers/implementation_iterator.js @@ -16,7 +16,7 @@ function implementation_iterator(description, specDefinitions, suite) { const implementation_description = description + ' with ' + key; const implementation = implementations[key]; - suite(implementation_description, specDefinitions.bind(null, implementation)); + suite(implementation_description, specDefinitions.bind(null, implementation, key)); }); } diff --git a/test/map-keys.js b/test/map-keys.js index fe60086..b5eff91 100644 --- a/test/map-keys.js +++ b/test/map-keys.js @@ -3,9 +3,12 @@ const path = require('path'); const { render, renderSync } = require('../src'); const { normalizePath } = require('../src/util'); -const mapKeysFile = path.join(__dirname, 'sass', 'map-keys.scss'); +const mapKeysFile = { + "Node Sass": path.join(__dirname, 'sass', 'map-keys_node-sass.scss'), + "Dart Sass": path.join(__dirname, 'sass', 'map-keys_dart-sass.scss'), +} -function verifyMapKeys(rendered, sourceFile) { +function verifyMapKeys(rendered, impl) { expect(rendered.vars).to.exist; expect(rendered.vars).to.have.property('global'); expect(rendered.vars.global).to.have.property('$map'); @@ -72,11 +75,17 @@ function verifyMapKeys(rendered, sourceFile) { expect(rendered.vars.global.$map.value['(d: map)'].value.nested).to.deep.include({ type: 'SassMap', }); - // TODO `node-sass` throws Error for the nested `(1, 2, 3)` key. The problem should be with node-sass itself, as it works OK with `sass`. - // expect(rendered.vars.global.$map.value['(d: map)'].value.nested.value).to.have.property('1,2,3'); - // expect(rendered.vars.global.$map.value['(d: map)'].value.nested.value['1,2,3']).to.deep.include({ - // type: 'SassString', value: 'list' - // }); + if(impl === "Node Sass") { + expect(rendered.vars.global.$map.value['(d: map)'].value.nested.value).to.have.property('1 2 3'); + expect(rendered.vars.global.$map.value['(d: map)'].value.nested.value['1 2 3']).to.deep.include({ + type: 'SassString', value: 'list' + }); + } else if(impl === "Dart Sass") { + expect(rendered.vars.global.$map.value['(d: map)'].value.nested.value).to.have.property('1,2,3'); + expect(rendered.vars.global.$map.value['(d: map)'].value.nested.value['1,2,3']).to.deep.include({ + type: 'SassString', value: 'list' + }); + } expect(rendered.vars.global.$map.value['(d: map)'].value.nested.value).to.have.property('1 2 3 4'); expect(rendered.vars.global.$map.value['(d: map)'].value.nested.value['1 2 3 4']).to.deep.include({ type: 'SassString', value: 'list-spaces' @@ -90,19 +99,19 @@ function verifyMapKeys(rendered, sourceFile) { }); } -describe_implementation('map-keys', (sass) => { +describe_implementation('map-keys', (sass, impl) => { describe('sync', () => { it('should extract all variables', () => { - const rendered = renderSync({ file: mapKeysFile }, { implementation: sass }); - verifyMapKeys(rendered, mapKeysFile); + const rendered = renderSync({ file: mapKeysFile[impl] }, { implementation: sass }); + verifyMapKeys(rendered, impl); }); }); describe('async', () => { it('should extract all variables', () => { - return render({ file: mapKeysFile }, { implementation: sass }) + return render({ file: mapKeysFile[impl] }, { implementation: sass }) .then(rendered => { - verifyMapKeys(rendered, mapKeysFile); + verifyMapKeys(rendered, impl); }); }); }); diff --git a/test/sass/map-keys.scss b/test/sass/map-keys_dart-sass.scss similarity index 74% rename from test/sass/map-keys.scss rename to test/sass/map-keys_dart-sass.scss index f8a911b..b4c2845 100644 --- a/test/sass/map-keys.scss +++ b/test/sass/map-keys_dart-sass.scss @@ -15,7 +15,7 @@ $map: ( ((b: 'nested'), (c: 'maps')): 'list-maps', (d: 'map'): ( nested: ( - //(1, 2, 3): 'list', // TODO `node-sass` throws Error for the nested `(1, 2, 3)` key. The problem should be with node-sass itself, as it works OK with `sass`. + (1, 2, 3): 'list', (1 2 3 4): 'list-spaces' ) ), diff --git a/test/sass/map-keys_node-sass.scss b/test/sass/map-keys_node-sass.scss new file mode 100644 index 0000000..2324ba5 --- /dev/null +++ b/test/sass/map-keys_node-sass.scss @@ -0,0 +1,24 @@ +$keyvar: 'somekey'; + +$map: ( + string: 1em, + 1px: 'number', + white: 'color-string', + #123456: 'color-hex', + rgba(0, 1, 2, 0.5): 'color-rgba', + rgb(0, 0, 0): 'color-black-rgba', + true: 'boolean', + null: 'null', + (1, 2, 3): 'list', + (1 2 3 4): 'list-spaces', + (a: 'map'): 'map', + ((b: 'nested'), (c: 'maps')): 'list-maps', + (d: 'map'): ( + nested: ( + (1 2 3): 'list', + (1 2 3 4): 'list-spaces' + ) + ), + darken(white, 1%): 'darkened-white', + $keyvar: 'key-variable', +);