Skip to content

Commit

Permalink
fix: map tests for incompatible node-sass syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
jgranstrom committed Nov 4, 2023
1 parent b11e34d commit 2c54b54
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 14 deletions.
2 changes: 1 addition & 1 deletion test/helpers/implementation_iterator.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
});
}

Expand Down
33 changes: 21 additions & 12 deletions test/map-keys.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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'
Expand All @@ -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);
});
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'
)
),
Expand Down
24 changes: 24 additions & 0 deletions test/sass/map-keys_node-sass.scss
Original file line number Diff line number Diff line change
@@ -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',
);

0 comments on commit 2c54b54

Please sign in to comment.