diff --git a/package-lock.json b/package-lock.json index e2badd7d..9c796f9b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -30,6 +30,7 @@ "node-sass": "^7.0.1", "postcss": "^8.4.5", "rimraf": "^3.0.2", + "sass": "^1.45.1", "vinyl": "^2.2.1" }, "engines": { @@ -3468,6 +3469,12 @@ "node": ">= 4" } }, + "node_modules/immutable": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/immutable/-/immutable-4.0.0.tgz", + "integrity": "sha512-zIE9hX70qew5qTUjSS7wi1iwj/l7+m54KWU247nhM3v806UdGj1yDndXj+IOYxxtW9zyLI+xqFNZjTuDaLUqFw==", + "dev": true + }, "node_modules/import-cwd": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/import-cwd/-/import-cwd-3.0.0.tgz", @@ -6765,6 +6772,23 @@ "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==", "dev": true }, + "node_modules/sass": { + "version": "1.45.1", + "resolved": "https://registry.npmjs.org/sass/-/sass-1.45.1.tgz", + "integrity": "sha512-pwPRiq29UR0o4X3fiQyCtrESldXvUQAAE0QmcJTpsI4kuHHcLzZ54M1oNBVIXybQv8QF2zfkpFcTxp8ta97dUA==", + "dev": true, + "dependencies": { + "chokidar": ">=3.0.0 <4.0.0", + "immutable": "^4.0.0", + "source-map-js": ">=0.6.2 <2.0.0" + }, + "bin": { + "sass": "sass.js" + }, + "engines": { + "node": ">=8.9.0" + } + }, "node_modules/sass-graph": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/sass-graph/-/sass-graph-4.0.0.tgz", @@ -6856,6 +6880,144 @@ "node": ">=12" } }, + "node_modules/sass/node_modules/anymatch": { + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/anymatch/-/anymatch-3.1.2.tgz", + "integrity": "sha512-P43ePfOAIupkguHUycrc4qJ9kz8ZiuOUijaETwX7THt0Y/GNK7v0aa8rY816xWjZ7rJdA5XdMcpVFTKMq+RvWg==", + "dev": true, + "dependencies": { + "normalize-path": "^3.0.0", + "picomatch": "^2.0.4" + }, + "engines": { + "node": ">= 8" + } + }, + "node_modules/sass/node_modules/binary-extensions": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/binary-extensions/-/binary-extensions-2.2.0.tgz", + "integrity": "sha512-jDctJ/IVQbZoJykoeHbhXpOlNBqGNcwXJKJog42E5HDPUwQTSdjCHdihjj0DlnheQ7blbT6dHOafNAiS8ooQKA==", + "dev": true, + "engines": { + "node": ">=8" + } + }, + "node_modules/sass/node_modules/braces": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/braces/-/braces-3.0.2.tgz", + "integrity": "sha512-b8um+L1RzM3WDSzvhm6gIz1yfTbBt6YTlcEKAvsmqCZZFw46z626lVj9j1yEPW33H5H+lBQpZMP1k8l+78Ha0A==", + "dev": true, + "dependencies": { + "fill-range": "^7.0.1" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/sass/node_modules/chokidar": { + "version": "3.5.2", + "resolved": "https://registry.npmjs.org/chokidar/-/chokidar-3.5.2.tgz", + "integrity": "sha512-ekGhOnNVPgT77r4K/U3GDhu+FQ2S8TnK/s2KbIGXi0SZWuwkZ2QNyfWdZW+TVfn84DpEP7rLeCt2UI6bJ8GwbQ==", + "dev": true, + "dependencies": { + "anymatch": "~3.1.2", + "braces": "~3.0.2", + "glob-parent": "~5.1.2", + "is-binary-path": "~2.1.0", + "is-glob": "~4.0.1", + "normalize-path": "~3.0.0", + "readdirp": "~3.6.0" + }, + "engines": { + "node": ">= 8.10.0" + }, + "optionalDependencies": { + "fsevents": "~2.3.2" + } + }, + "node_modules/sass/node_modules/fill-range": { + "version": "7.0.1", + "resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.0.1.tgz", + "integrity": "sha512-qOo9F+dMUmC2Lcb4BbVvnKJxTPjCm+RRpe4gDuGrzkL7mEVl/djYSu2OdQ2Pa302N4oqkSg9ir6jaLWJ2USVpQ==", + "dev": true, + "dependencies": { + "to-regex-range": "^5.0.1" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/sass/node_modules/fsevents": { + "version": "2.3.2", + "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.2.tgz", + "integrity": "sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==", + "dev": true, + "hasInstallScript": true, + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": "^8.16.0 || ^10.6.0 || >=11.0.0" + } + }, + "node_modules/sass/node_modules/glob-parent": { + "version": "5.1.2", + "resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-5.1.2.tgz", + "integrity": "sha512-AOIgSQCepiJYwP3ARnGx+5VnTu2HBYdzbGP45eLw1vr3zB3vZLeyed1sC9hnbcOc9/SrMyM5RPQrkGz4aS9Zow==", + "dev": true, + "dependencies": { + "is-glob": "^4.0.1" + }, + "engines": { + "node": ">= 6" + } + }, + "node_modules/sass/node_modules/is-binary-path": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/is-binary-path/-/is-binary-path-2.1.0.tgz", + "integrity": "sha512-ZMERYes6pDydyuGidse7OsHxtbI7WVeUEozgR/g7rd0xUimYNlvZRE/K2MgZTjWy725IfelLeVcEM97mmtRGXw==", + "dev": true, + "dependencies": { + "binary-extensions": "^2.0.0" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/sass/node_modules/is-number": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/is-number/-/is-number-7.0.0.tgz", + "integrity": "sha512-41Cifkg6e8TylSpdtTpeLVMqvSBEVzTttHvERD741+pnZ8ANv0004MRL43QKPDlK9cGvNp6NZWZUBlbGXYxxng==", + "dev": true, + "engines": { + "node": ">=0.12.0" + } + }, + "node_modules/sass/node_modules/readdirp": { + "version": "3.6.0", + "resolved": "https://registry.npmjs.org/readdirp/-/readdirp-3.6.0.tgz", + "integrity": "sha512-hOS089on8RduqdbhvQ5Z37A0ESjsqz6qnRcffsMU3495FuTdqSm+7bhJ29JvIOsBDEEnan5DPu9t3To9VRlMzA==", + "dev": true, + "dependencies": { + "picomatch": "^2.2.1" + }, + "engines": { + "node": ">=8.10.0" + } + }, + "node_modules/sass/node_modules/to-regex-range": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/to-regex-range/-/to-regex-range-5.0.1.tgz", + "integrity": "sha512-65P7iz6X5yEr1cwcgvQxbbIw7Uk3gOy5dIdtZ4rDveLqhrdJP+Li/Hx6tyK0NEb+2GCyneCMJiGqrADCSNk8sQ==", + "dev": true, + "dependencies": { + "is-number": "^7.0.0" + }, + "engines": { + "node": ">=8.0" + } + }, "node_modules/scss-tokenizer": { "version": "0.3.0", "resolved": "https://registry.npmjs.org/scss-tokenizer/-/scss-tokenizer-0.3.0.tgz", @@ -11383,6 +11545,12 @@ "integrity": "sha512-cyFDKrqc/YdcWFniJhzI42+AzS+gNwmUzOSFcRCQYwySuBBBy/KjuxWLZ/FHEH6Moq1NizMOBWyTcv8O4OZIMg==", "dev": true }, + "immutable": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/immutable/-/immutable-4.0.0.tgz", + "integrity": "sha512-zIE9hX70qew5qTUjSS7wi1iwj/l7+m54KWU247nhM3v806UdGj1yDndXj+IOYxxtW9zyLI+xqFNZjTuDaLUqFw==", + "dev": true + }, "import-cwd": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/import-cwd/-/import-cwd-3.0.0.tgz", @@ -13899,6 +14067,118 @@ "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==", "dev": true }, + "sass": { + "version": "1.45.1", + "resolved": "https://registry.npmjs.org/sass/-/sass-1.45.1.tgz", + "integrity": "sha512-pwPRiq29UR0o4X3fiQyCtrESldXvUQAAE0QmcJTpsI4kuHHcLzZ54M1oNBVIXybQv8QF2zfkpFcTxp8ta97dUA==", + "dev": true, + "requires": { + "chokidar": ">=3.0.0 <4.0.0", + "immutable": "^4.0.0", + "source-map-js": ">=0.6.2 <2.0.0" + }, + "dependencies": { + "anymatch": { + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/anymatch/-/anymatch-3.1.2.tgz", + "integrity": "sha512-P43ePfOAIupkguHUycrc4qJ9kz8ZiuOUijaETwX7THt0Y/GNK7v0aa8rY816xWjZ7rJdA5XdMcpVFTKMq+RvWg==", + "dev": true, + "requires": { + "normalize-path": "^3.0.0", + "picomatch": "^2.0.4" + } + }, + "binary-extensions": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/binary-extensions/-/binary-extensions-2.2.0.tgz", + "integrity": "sha512-jDctJ/IVQbZoJykoeHbhXpOlNBqGNcwXJKJog42E5HDPUwQTSdjCHdihjj0DlnheQ7blbT6dHOafNAiS8ooQKA==", + "dev": true + }, + "braces": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/braces/-/braces-3.0.2.tgz", + "integrity": "sha512-b8um+L1RzM3WDSzvhm6gIz1yfTbBt6YTlcEKAvsmqCZZFw46z626lVj9j1yEPW33H5H+lBQpZMP1k8l+78Ha0A==", + "dev": true, + "requires": { + "fill-range": "^7.0.1" + } + }, + "chokidar": { + "version": "3.5.2", + "resolved": "https://registry.npmjs.org/chokidar/-/chokidar-3.5.2.tgz", + "integrity": "sha512-ekGhOnNVPgT77r4K/U3GDhu+FQ2S8TnK/s2KbIGXi0SZWuwkZ2QNyfWdZW+TVfn84DpEP7rLeCt2UI6bJ8GwbQ==", + "dev": true, + "requires": { + "anymatch": "~3.1.2", + "braces": "~3.0.2", + "fsevents": "~2.3.2", + "glob-parent": "~5.1.2", + "is-binary-path": "~2.1.0", + "is-glob": "~4.0.1", + "normalize-path": "~3.0.0", + "readdirp": "~3.6.0" + } + }, + "fill-range": { + "version": "7.0.1", + "resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.0.1.tgz", + "integrity": "sha512-qOo9F+dMUmC2Lcb4BbVvnKJxTPjCm+RRpe4gDuGrzkL7mEVl/djYSu2OdQ2Pa302N4oqkSg9ir6jaLWJ2USVpQ==", + "dev": true, + "requires": { + "to-regex-range": "^5.0.1" + } + }, + "fsevents": { + "version": "2.3.2", + "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.2.tgz", + "integrity": "sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==", + "dev": true, + "optional": true + }, + "glob-parent": { + "version": "5.1.2", + "resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-5.1.2.tgz", + "integrity": "sha512-AOIgSQCepiJYwP3ARnGx+5VnTu2HBYdzbGP45eLw1vr3zB3vZLeyed1sC9hnbcOc9/SrMyM5RPQrkGz4aS9Zow==", + "dev": true, + "requires": { + "is-glob": "^4.0.1" + } + }, + "is-binary-path": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/is-binary-path/-/is-binary-path-2.1.0.tgz", + "integrity": "sha512-ZMERYes6pDydyuGidse7OsHxtbI7WVeUEozgR/g7rd0xUimYNlvZRE/K2MgZTjWy725IfelLeVcEM97mmtRGXw==", + "dev": true, + "requires": { + "binary-extensions": "^2.0.0" + } + }, + "is-number": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/is-number/-/is-number-7.0.0.tgz", + "integrity": "sha512-41Cifkg6e8TylSpdtTpeLVMqvSBEVzTttHvERD741+pnZ8ANv0004MRL43QKPDlK9cGvNp6NZWZUBlbGXYxxng==", + "dev": true + }, + "readdirp": { + "version": "3.6.0", + "resolved": "https://registry.npmjs.org/readdirp/-/readdirp-3.6.0.tgz", + "integrity": "sha512-hOS089on8RduqdbhvQ5Z37A0ESjsqz6qnRcffsMU3495FuTdqSm+7bhJ29JvIOsBDEEnan5DPu9t3To9VRlMzA==", + "dev": true, + "requires": { + "picomatch": "^2.2.1" + } + }, + "to-regex-range": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/to-regex-range/-/to-regex-range-5.0.1.tgz", + "integrity": "sha512-65P7iz6X5yEr1cwcgvQxbbIw7Uk3gOy5dIdtZ4rDveLqhrdJP+Li/Hx6tyK0NEb+2GCyneCMJiGqrADCSNk8sQ==", + "dev": true, + "requires": { + "is-number": "^7.0.0" + } + } + } + }, "sass-graph": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/sass-graph/-/sass-graph-4.0.0.tgz", diff --git a/package.json b/package.json index 7e9728d8..c746e398 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,9 @@ "lint": "eslint --report-unused-disable-directives --ignore-path .gitignore .", "fix": "npm run lint -- --fix", "mocha": "mocha", - "test": "mocha" + "test": "npm run test:node-sass && npm run test:dart-sass", + "test:node-sass": "mocha", + "test:dart-sass": "mocha -- --sass" }, "repository": { "type": "git", @@ -52,6 +54,7 @@ "node-sass": "^7.0.1", "postcss": "^8.4.5", "rimraf": "^3.0.2", + "sass": "^1.45.1", "vinyl": "^2.2.1" } } diff --git a/test/expected-sass/empty.css b/test/expected-sass/empty.css new file mode 100644 index 00000000..e69de29b diff --git a/test/expected-sass/indent.css b/test/expected-sass/indent.css new file mode 100644 index 00000000..aea958f4 --- /dev/null +++ b/test/expected-sass/indent.css @@ -0,0 +1,3 @@ +body .div { + color: blue; +} \ No newline at end of file diff --git a/test/expected-sass/inheritance.css b/test/expected-sass/inheritance.css new file mode 100644 index 00000000..b3602a37 --- /dev/null +++ b/test/expected-sass/inheritance.css @@ -0,0 +1,21 @@ +body { + background: pink; +} + +footer { + background: red; +} + +.error, .badError { + border: #f00; + background: #fdd; +} + +.error.intrusion, .intrusion.badError { + font-size: 1.3em; + font-weight: bold; +} + +.badError { + border-width: 3px; +} \ No newline at end of file diff --git a/test/expected-sass/mixins.css b/test/expected-sass/mixins.css new file mode 100644 index 00000000..67753a0d --- /dev/null +++ b/test/expected-sass/mixins.css @@ -0,0 +1,11 @@ +#data { + float: left; + margin-left: 10px; +} +#data th { + text-align: center; + font-weight: bold; +} +#data td, #data th { + padding: 2px; +} \ No newline at end of file diff --git a/test/expected-sass/variables.css b/test/expected-sass/variables.css new file mode 100644 index 00000000..03815448 --- /dev/null +++ b/test/expected-sass/variables.css @@ -0,0 +1,10 @@ +.content-navigation { + border-color: #3bbfce; + color: #2ca2af; +} + +.border { + padding: 8px; + margin: 8px; + border-color: #3bbfce; +} \ No newline at end of file diff --git a/test/main.js b/test/main.js index 39f8b851..b8bbdb6d 100644 --- a/test/main.js +++ b/test/main.js @@ -12,7 +12,12 @@ const autoprefixer = require('autoprefixer'); const tap = require('gulp-tap'); const globule = require('globule'); -const sass = require('../index')(require('node-sass')); +const COMPILER = process.argv.includes('--sass') ? 'sass' : 'node-sass'; + +// eslint-disable-next-line import/no-dynamic-require +const sass = require('../index')(require(COMPILER)); + +const expectedTestsPath = COMPILER === 'sass' ? 'expected-sass' : 'expected'; const createVinyl = (filename, contents) => { const base = path.join(__dirname, 'scss'); @@ -72,7 +77,7 @@ describe('gulp-sass -- async compile', () => { assert.ok(cssFile.contents); assert.equal(path.basename(cssFile.path), 'empty.css'); - const actual = fs.readFileSync(path.join(__dirname, 'expected', 'empty.css'), 'utf8'); + const actual = fs.readFileSync(path.join(__dirname, expectedTestsPath, 'empty.css'), 'utf8'); assert.equal(String(normaliseEOL(cssFile.contents)), normaliseEOL(actual)); done(); }); @@ -88,7 +93,7 @@ describe('gulp-sass -- async compile', () => { assert.ok(cssFile.relative); assert.ok(cssFile.contents); - const actual = fs.readFileSync(path.join(__dirname, 'expected', 'mixins.css'), 'utf8'); + const actual = fs.readFileSync(path.join(__dirname, expectedTestsPath, 'mixins.css'), 'utf8'); assert.equal(String(normaliseEOL(cssFile.contents)), normaliseEOL(actual)); done(); }); @@ -102,7 +107,7 @@ describe('gulp-sass -- async compile', () => { ]; const stream = sass(); let mustSee = files.length; - let expectedPath = path.join('expected', 'mixins.css'); + let expectedPath = path.join(expectedTestsPath, 'mixins.css'); stream.on('data', (cssFile) => { assert.ok(cssFile); @@ -110,7 +115,7 @@ describe('gulp-sass -- async compile', () => { assert.ok(cssFile.relative); assert.ok(cssFile.contents); if (cssFile.path.includes('variables')) { - expectedPath = path.join('expected', 'variables.css'); + expectedPath = path.join(expectedTestsPath, 'variables.css'); } const actual = fs.readFileSync(path.join(__dirname, expectedPath), 'utf8'); @@ -136,7 +141,7 @@ describe('gulp-sass -- async compile', () => { assert.ok(cssFile.relative); assert.ok(cssFile.contents); - const actual = fs.readFileSync(path.join(__dirname, 'expected', 'inheritance.css'), 'utf8'); + const actual = fs.readFileSync(path.join(__dirname, expectedTestsPath, 'inheritance.css'), 'utf8'); assert.equal(String(normaliseEOL(cssFile.contents)), normaliseEOL(actual)); done(); }); @@ -158,11 +163,12 @@ describe('gulp-sass -- async compile', () => { stream.on('error', (err) => { // Error must include message body - assert.equal(err.message.includes('property "font" must be followed by a \':\''), true); + const messageBody = COMPILER === 'sass' + ? 'Error: expected "{"' + : 'property "font" must be followed by a \':\''; + assert.equal(err.message.includes(messageBody), true); // Error must include file error occurs in - assert.equal(err.message.includes('test', 'scss', 'error.scss'), true); - // Error must include line and column error occurs on - assert.equal(err.message.includes('on line 2'), true); + assert.equal(err.message.includes(path.normalize('test/scss/error.scss')), true); // Error must include relativePath property assert.equal(err.relativePath, path.join('test', 'scss', 'error.scss')); done(); @@ -176,7 +182,10 @@ describe('gulp-sass -- async compile', () => { stream.on('error', (err) => { // Error must include original error message - assert.equal(err.messageOriginal.includes('property "font" must be followed by a \':\''), true); + const message = COMPILER === 'sass' + ? 'expected "{"' + : 'property "font" must be followed by a \':\''; + assert.equal(err.messageOriginal.includes(message), true); // Error must not format or change the original error message assert.equal(err.messageOriginal.includes('on line 2'), false); done(); @@ -197,7 +206,7 @@ describe('gulp-sass -- async compile', () => { assert.ok(cssFile.relative); assert.ok(cssFile.contents); - const actual = fs.readFileSync(path.join(__dirname, 'expected', 'mixins.css'), 'utf8'); + const actual = fs.readFileSync(path.join(__dirname, expectedTestsPath, 'mixins.css'), 'utf8'); assert.equal(String(normaliseEOL(cssFile.contents)), normaliseEOL(actual)); done(); }); @@ -216,7 +225,7 @@ describe('gulp-sass -- async compile', () => { assert.ok(cssFile.relative); assert.ok(cssFile.contents); - const actual = fs.readFileSync(path.join(__dirname, 'expected', 'mixins.css'), 'utf8'); + const actual = fs.readFileSync(path.join(__dirname, expectedTestsPath, 'mixins.css'), 'utf8'); assert.equal(String(normaliseEOL(cssFile.contents)), `/* Added Dynamically */\n${normaliseEOL(actual)}`); done(); }); @@ -245,7 +254,7 @@ describe('gulp-sass -- async compile', () => { const stream = sass(); stream.on('data', (cssFile) => { assert.ok(cssFile.sourceMap); - assert.deepEqual(cssFile.sourceMap.sources, expectedSources); + assert.deepEqual(cssFile.sourceMap.sources.sort(), expectedSources.sort()); done(); }); stream.write(sassFile); @@ -260,7 +269,7 @@ describe('gulp-sass -- async compile', () => { assert.ok(cssFile.relative); assert.ok(cssFile.contents); - const actual = fs.readFileSync(path.join(__dirname, 'expected', 'indent.css'), 'utf8'); + const actual = fs.readFileSync(path.join(__dirname, expectedTestsPath, 'indent.css'), 'utf8'); assert.equal(String(normaliseEOL(cssFile.contents)), normaliseEOL(actual)); done(); }); @@ -274,7 +283,7 @@ describe('gulp-sass -- async compile', () => { ]; const stream = sass(); let mustSee = files.length; - let expectedPath = path.join('expected', 'mixins.css'); + let expectedPath = path.join(expectedTestsPath, 'mixins.css'); stream.on('data', (cssFile) => { assert.ok(cssFile); @@ -282,7 +291,7 @@ describe('gulp-sass -- async compile', () => { assert.ok(cssFile.relative); assert.ok(cssFile.contents); if (cssFile.path.includes('indent')) { - expectedPath = path.join('expected', 'indent.css'); + expectedPath = path.join(expectedTestsPath, 'indent.css'); } const actual = fs.readFileSync(path.join(__dirname, expectedPath), 'utf8'); @@ -339,7 +348,7 @@ describe('gulp-sass -- sync compile', () => { assert.ok(cssFile.relative); assert.ok(cssFile.contents); - const actual = fs.readFileSync(path.join(__dirname, 'expected', 'mixins.css'), 'utf8'); + const actual = fs.readFileSync(path.join(__dirname, expectedTestsPath, 'mixins.css'), 'utf8'); assert.equal(String(normaliseEOL(cssFile.contents)), normaliseEOL(actual)); done(); }); @@ -353,7 +362,7 @@ describe('gulp-sass -- sync compile', () => { ]; const stream = sass.sync(); let mustSee = files.length; - let expectedPath = path.join('expected', 'mixins.css'); + let expectedPath = path.join(expectedTestsPath, 'mixins.css'); stream.on('data', (cssFile) => { assert.ok(cssFile); @@ -362,7 +371,7 @@ describe('gulp-sass -- sync compile', () => { assert.ok(cssFile.contents); if (cssFile.path.includes('variables')) { - expectedPath = path.join('expected', 'variables.css'); + expectedPath = path.join(expectedTestsPath, 'variables.css'); } const actual = normaliseEOL(fs.readFileSync(path.join(__dirname, expectedPath), 'utf8')); @@ -389,7 +398,7 @@ describe('gulp-sass -- sync compile', () => { assert.ok(cssFile.relative); assert.ok(cssFile.contents); - const actual = fs.readFileSync(path.join(__dirname, 'expected', 'inheritance.css'), 'utf8'); + const actual = fs.readFileSync(path.join(__dirname, expectedTestsPath, 'inheritance.css'), 'utf8'); assert.equal(String(normaliseEOL(cssFile.contents)), normaliseEOL(actual)); done(); }); @@ -401,7 +410,11 @@ describe('gulp-sass -- sync compile', () => { const stream = sass.sync(); stream.on('error', (err) => { - assert.equal(err.message.includes('property "font" must be followed by a \':\''), true); + // Error must include message body + const messageBody = COMPILER === 'sass' + ? 'Error: expected "{"' + : 'property "font" must be followed by a \':\''; + assert.equal(err.message.includes(messageBody), true); assert.equal(err.relativePath, path.join('test', 'scss', 'error.scss')); done(); }); @@ -439,7 +452,7 @@ describe('gulp-sass -- sync compile', () => { const stream = sass.sync(); stream.on('data', (cssFile) => { assert.ok(cssFile.sourceMap); - assert.deepEqual(cssFile.sourceMap.sources, expectedSources); + assert.deepEqual(cssFile.sourceMap.sources.sort(), expectedSources.sort()); done(); }); stream.write(sassFile); @@ -458,19 +471,21 @@ describe('gulp-sass -- sync compile', () => { 'inheritance.scss', ]; + if (COMPILER === 'sass') expectedSourcesAfter.push('inheritance.css'); + gulp.src(path.join(__dirname, 'scss', 'inheritance.scss')) .pipe(sourcemaps.init()) .pipe(sass.sync()) .pipe(tap((file) => { assert.ok(file.sourceMap); - assert.deepEqual(file.sourceMap.sources, expectedSourcesBefore); + assert.deepEqual(file.sourceMap.sources.sort(), expectedSourcesBefore.sort()); })) .pipe(postcss([autoprefixer()])) .pipe(sourcemaps.write()) .pipe(gulp.dest(path.join(__dirname, 'results'))) .pipe(tap((file) => { assert.ok(file.sourceMap); - assert.deepEqual(file.sourceMap.sources, expectedSourcesAfter); + assert.deepEqual(file.sourceMap.sources.sort(), expectedSourcesAfter.sort()); })); done(); }); @@ -510,17 +525,19 @@ describe('gulp-sass -- sync compile', () => { 'scss/inheritance.scss', ]; + if (COMPILER === 'sass') expectedSourcesAfter.push('scss/inheritance.css'); + gulp.src(path.join(__dirname, 'scss', 'inheritance.scss'), { base: 'test' }) .pipe(sourcemaps.init()) .pipe(sass.sync()) .pipe(tap((file) => { assert.ok(file.sourceMap); - assert.deepEqual(file.sourceMap.sources, expectedSourcesBefore); + assert.deepEqual(file.sourceMap.sources.sort(), expectedSourcesBefore.sort()); })) .pipe(postcss([autoprefixer()])) .pipe(tap((file) => { assert.ok(file.sourceMap); - assert.deepEqual(file.sourceMap.sources, expectedSourcesAfter); + assert.deepEqual(file.sourceMap.sources.sort(), expectedSourcesAfter.sort()); })); done(); }); diff --git a/test/scss/includes/_dogs.sass b/test/scss/includes/_dogs.sass index fbdee6e4..c7261da8 100644 --- a/test/scss/includes/_dogs.sass +++ b/test/scss/includes/_dogs.sass @@ -1,5 +1,5 @@ -$blue: #3bbfce; -$margin: 16px; +$blue: #3bbfce +$margin: 16px footer - background: red; + background: red