Skip to content

Commit dc23895

Browse files
refactor: code (#725)
1 parent 97c93dd commit dc23895

File tree

7 files changed

+128
-66
lines changed

7 files changed

+128
-66
lines changed

test/helpers/getCode.js renamed to test/helpers/getCodeFromBundle.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const vm = require('vm');
22

3-
function getCode(stats, assetName) {
3+
function getCodeFromBundle(stats, assetName) {
44
let code = null;
55

66
if (
@@ -23,4 +23,4 @@ function getCode(stats, assetName) {
2323
return result.default;
2424
}
2525

26-
export default getCode;
26+
export default getCodeFromBundle;

test/helpers/getPureCode.js renamed to test/helpers/getCodeFromSass.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import path from 'path';
22
import os from 'os';
33
import fs from 'fs';
44

5-
function getPureCode(testId, options) {
5+
function getCodeFromSass(testId, options) {
66
const sassOptions = Object.assign({}, options);
77

88
const { implementation } = sassOptions;
@@ -646,9 +646,9 @@ function getPureCode(testId, options) {
646646
? [sassOptions.importer, testImporter]
647647
: [testImporter];
648648

649-
const { css } = implementation.renderSync(sassOptions);
649+
const { css, map } = implementation.renderSync(sassOptions);
650650

651-
return css.toString();
651+
return { css: css.toString(), sourceMap: map };
652652
}
653653

654-
export default getPureCode;
654+
export default getCodeFromSass;

test/helpers/index.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import compile from './compiler';
22
import getTestId from './getTestId';
3-
import getCode from './getCode';
4-
import getPureCode from './getPureCode';
3+
import getCodeFromBundle from './getCodeFromBundle';
4+
import getCodeFromSass from './getCodeFromSass';
55
import getImplementationByName from './getImplementationByName';
66
import normalizeError from './normalizeError';
77

88
export {
99
compile,
1010
getTestId,
11-
getCode,
12-
getPureCode,
11+
getCodeFromBundle,
12+
getCodeFromSass,
1313
getImplementationByName,
1414
normalizeError,
1515
};

test/helpers/testLoader.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use strict';
22

33
function testLoader(content, sourceMap) {
4-
const result = { content };
4+
const result = { css: content };
55

66
if (sourceMap) {
77
result.sourceMap = sourceMap;

test/implementation-option.test.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import dartSass from 'sass';
88
import {
99
compile,
1010
getTestId,
11-
getCode,
11+
getCodeFromBundle,
1212
getImplementationByName,
1313
normalizeError,
1414
} from './helpers';
@@ -32,9 +32,9 @@ describe('implementation option', () => {
3232
implementation: getImplementationByName(implementationName),
3333
};
3434
const stats = await compile(testId, { loader: { options } });
35-
const { content, sourceMap } = getCode(stats);
35+
const { css, sourceMap } = getCodeFromBundle(stats);
3636

37-
expect(content).toBeDefined();
37+
expect(css).toBeDefined();
3838
expect(sourceMap).toBeUndefined();
3939

4040
expect(stats.compilation.warnings).toMatchSnapshot('warnings');
@@ -57,9 +57,9 @@ describe('implementation option', () => {
5757
const testId = getTestId('language', 'scss');
5858
const options = {};
5959
const stats = await compile(testId, { loader: { options } });
60-
const { content, sourceMap } = getCode(stats);
60+
const { css, sourceMap } = getCodeFromBundle(stats);
6161

62-
expect(content).toBeDefined();
62+
expect(css).toBeDefined();
6363
expect(sourceMap).toBeUndefined();
6464

6565
expect(stats.compilation.warnings).toMatchSnapshot('warnings');
@@ -80,7 +80,7 @@ describe('implementation option', () => {
8080
try {
8181
const stats = await compile(testId, { loader: { options } });
8282

83-
getCode(stats);
83+
getCodeFromBundle(stats);
8484
} catch (error) {
8585
expect(normalizeError(error)).toMatchSnapshot();
8686
}
@@ -97,7 +97,7 @@ describe('implementation option', () => {
9797
try {
9898
const stats = await compile(testId, { loader: { options } });
9999

100-
getCode(stats);
100+
getCodeFromBundle(stats);
101101
} catch (error) {
102102
expect(normalizeError(error)).toMatchSnapshot();
103103
}
@@ -114,7 +114,7 @@ describe('implementation option', () => {
114114
try {
115115
const stats = await compile(testId, { loader: { options } });
116116

117-
getCode(stats);
117+
getCodeFromBundle(stats);
118118
} catch (error) {
119119
expect(normalizeError(error)).toMatchSnapshot();
120120
}
@@ -129,7 +129,7 @@ describe('implementation option', () => {
129129
try {
130130
const stats = await compile(testId, { loader: { options } });
131131

132-
getCode(stats);
132+
getCodeFromBundle(stats);
133133
} catch (error) {
134134
expect(normalizeError(error)).toMatchSnapshot();
135135
}
@@ -144,7 +144,7 @@ describe('implementation option', () => {
144144
try {
145145
const stats = await compile(testId, { loader: { options } });
146146

147-
getCode(stats);
147+
getCodeFromBundle(stats);
148148
} catch (error) {
149149
expect(normalizeError(error)).toMatchSnapshot();
150150
}
@@ -160,7 +160,7 @@ describe('implementation option', () => {
160160
try {
161161
const stats = await compile(testId, { loader: { options } });
162162

163-
getCode(stats);
163+
getCodeFromBundle(stats);
164164
} catch (error) {
165165
expect(normalizeError(error)).toMatchSnapshot();
166166
}
@@ -191,7 +191,7 @@ describe('implementation option', () => {
191191
try {
192192
const stats = await compile(testId, { loader: { options } });
193193

194-
getCode(stats);
194+
getCodeFromBundle(stats);
195195
} catch (error) {
196196
expect(error).toMatchSnapshot();
197197
}

0 commit comments

Comments
 (0)