Skip to content

Commit f6c3e35

Browse files
committed
Introduce modern api and associated tests
1 parent d3e1a18 commit f6c3e35

File tree

3 files changed

+29
-4
lines changed

3 files changed

+29
-4
lines changed

gruntfile.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,15 @@ module.exports = grunt => {
1313
'test/tmp/compile2.css': 'test/fixtures/test.scss'
1414
}
1515
},
16+
modernCompile: {
17+
options: {
18+
api: 'modern'
19+
},
20+
files: {
21+
'test/tmp/modern-compile.css': 'test/fixtures/test.scss',
22+
'test/tmp/modern-compile2.css': 'test/fixtures/test.scss'
23+
}
24+
},
1625
includePaths: {
1726
options: {
1827
includePaths: ['test/fixtures']

tasks/sass.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,20 @@ module.exports = grunt => {
1919
(async () => {
2020
await Promise.all(this.files.map(async item => {
2121
const [src] = item.src;
22+
let result;
2223

2324
if (!src || path.basename(src)[0] === '_') {
2425
return;
2526
}
2627

27-
const result = await util.promisify(options.implementation.render)(Object.assign({}, options, {
28-
file: src,
29-
outFile: item.dest
30-
}));
28+
if (options.api === 'modern') {
29+
result = await options.implementation.compileAsync(src, options);
30+
} else {
31+
result = await util.promisify(options.implementation.render)(Object.assign({}, options, {
32+
file: src,
33+
outFile: item.dest
34+
}));
35+
}
3136

3237
grunt.file.write(item.dest, result.css);
3338

test/test.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,17 @@ exports.sass = {
1313

1414
test.done();
1515
},
16+
modernCompile(test) {
17+
test.expect(2);
18+
19+
const actual = grunt.file.read('test/tmp/modern-compile.css');
20+
const actual2 = grunt.file.read('test/tmp/modern-compile2.css');
21+
const expected = grunt.file.read('test/expected/compile.css');
22+
test.equal(actual, expected, 'should compile SCSS to CSS');
23+
test.equal(actual2, expected, 'should compile SCSS to CSS');
24+
25+
test.done();
26+
},
1627
includePaths(test) {
1728
test.expect(1);
1829

0 commit comments

Comments
 (0)