Skip to content

Commit

Permalink
fix: avoid different content on different os (#832)
Browse files Browse the repository at this point in the history
  • Loading branch information
evilebottnawi committed Apr 16, 2020
1 parent 1655baf commit 68dd278
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 8 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/nodejs.yml
Expand Up @@ -61,6 +61,10 @@ jobs:
runs-on: ${{ matrix.os }}

steps:
- name: Setup Git
if: matrix.os == 'windows-latest'
run: git config --global core.autocrlf input

- uses: actions/checkout@v2

- name: Use Node.js ${{ matrix.node-version }}
Expand Down
5 changes: 2 additions & 3 deletions src/getSassOptions.js
@@ -1,4 +1,3 @@
import os from 'os';
import path from 'path';

import cloneDeep from 'clone-deep';
Expand Down Expand Up @@ -60,8 +59,8 @@ function getSassOptions(loaderContext, loaderOptions, content, implementation) {

options.data = loaderOptions.prependData
? typeof loaderOptions.prependData === 'function'
? loaderOptions.prependData(loaderContext) + os.EOL + content
: loaderOptions.prependData + os.EOL + content
? `${loaderOptions.prependData(loaderContext)}\n${content}`
: `${loaderOptions.prependData}\n${content}`
: content;

// opt.outputStyle
Expand Down
54 changes: 54 additions & 0 deletions test/__snapshots__/prependData-option.test.js.snap
@@ -1,5 +1,59 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`prependData option should use same EOL on all os (dart-sass) (sass): css 1`] = `
"a {
color: hotpink;
}
body {
color: hotpink;
}"
`;

exports[`prependData option should use same EOL on all os (dart-sass) (sass): errors 1`] = `Array []`;

exports[`prependData option should use same EOL on all os (dart-sass) (sass): warnings 1`] = `Array []`;

exports[`prependData option should use same EOL on all os (dart-sass) (scss): css 1`] = `
"a {
color: red;
}
body {
color: hotpink;
}"
`;

exports[`prependData option should use same EOL on all os (dart-sass) (scss): errors 1`] = `Array []`;

exports[`prependData option should use same EOL on all os (dart-sass) (scss): warnings 1`] = `Array []`;

exports[`prependData option should use same EOL on all os (node-sass) (sass): css 1`] = `
"a {
color: hotpink; }
body {
color: hotpink; }
"
`;

exports[`prependData option should use same EOL on all os (node-sass) (sass): errors 1`] = `Array []`;

exports[`prependData option should use same EOL on all os (node-sass) (sass): warnings 1`] = `Array []`;

exports[`prependData option should use same EOL on all os (node-sass) (scss): css 1`] = `
"a {
color: red; }
body {
color: hotpink; }
"
`;

exports[`prependData option should use same EOL on all os (node-sass) (scss): errors 1`] = `Array []`;

exports[`prependData option should use same EOL on all os (node-sass) (scss): warnings 1`] = `Array []`;

exports[`prependData option should work with the "data" option as a function (dart-sass) (sass): css 1`] = `
"body {
color: hotpink;
Expand Down
6 changes: 1 addition & 5 deletions test/helpers/getCodeFromSass.js
@@ -1,5 +1,4 @@
import path from 'path';
import os from 'os';
import fs from 'fs';

function getCodeFromSass(testId, options) {
Expand All @@ -23,10 +22,7 @@ function getCodeFromSass(testId, options) {
sassOptions.indentedSyntax = isSass;
sassOptions.data = `$prepended-data: hotpink${
sassOptions.indentedSyntax ? '\n' : ';'
}${os.EOL}${fs.readFileSync(
path.resolve(__dirname, '..', testId),
'utf8'
)}`;
}\n${fs.readFileSync(path.resolve(__dirname, '..', testId), 'utf8')}`;
} else {
sassOptions.file = path.resolve(__dirname, '..', testId);
}
Expand Down
24 changes: 24 additions & 0 deletions test/prependData-option.test.js
Expand Up @@ -65,6 +65,30 @@ describe('prependData option', () => {
expect(getWarnings(stats)).toMatchSnapshot('warnings');
expect(getErrors(stats)).toMatchSnapshot('errors');
});

it(`should use same EOL on all os (${implementationName}) (${syntax})`, async () => {
const testId = getTestId('prepending-data', syntax);
const prependData =
syntax === 'sass'
? `$prepended-data: hotpink
a
color: $prepended-data`
: `$prepended-data: hotpink;
a {
color: red;
}`;
const options = {
implementation: getImplementationByName(implementationName),
prependData,
};
const compiler = getCompiler(testId, { loader: { options } });
const stats = await compile(compiler);
const codeFromBundle = getCodeFromBundle(stats, compiler);

expect(codeFromBundle.css).toMatchSnapshot('css');
expect(getWarnings(stats)).toMatchSnapshot('warnings');
expect(getErrors(stats)).toMatchSnapshot('errors');
});
});
});
});

0 comments on commit 68dd278

Please sign in to comment.