Skip to content

Commit

Permalink
refactor: code (#725)
Browse files Browse the repository at this point in the history
  • Loading branch information
evilebottnawi committed Aug 16, 2019
1 parent 97c93dd commit dc23895
Show file tree
Hide file tree
Showing 7 changed files with 128 additions and 66 deletions.
4 changes: 2 additions & 2 deletions test/helpers/getCode.js → test/helpers/getCodeFromBundle.js
@@ -1,6 +1,6 @@
const vm = require('vm');

function getCode(stats, assetName) {
function getCodeFromBundle(stats, assetName) {
let code = null;

if (
Expand All @@ -23,4 +23,4 @@ function getCode(stats, assetName) {
return result.default;
}

export default getCode;
export default getCodeFromBundle;
Expand Up @@ -2,7 +2,7 @@ import path from 'path';
import os from 'os';
import fs from 'fs';

function getPureCode(testId, options) {
function getCodeFromSass(testId, options) {
const sassOptions = Object.assign({}, options);

const { implementation } = sassOptions;
Expand Down Expand Up @@ -646,9 +646,9 @@ function getPureCode(testId, options) {
? [sassOptions.importer, testImporter]
: [testImporter];

const { css } = implementation.renderSync(sassOptions);
const { css, map } = implementation.renderSync(sassOptions);

return css.toString();
return { css: css.toString(), sourceMap: map };
}

export default getPureCode;
export default getCodeFromSass;
8 changes: 4 additions & 4 deletions test/helpers/index.js
@@ -1,15 +1,15 @@
import compile from './compiler';
import getTestId from './getTestId';
import getCode from './getCode';
import getPureCode from './getPureCode';
import getCodeFromBundle from './getCodeFromBundle';
import getCodeFromSass from './getCodeFromSass';
import getImplementationByName from './getImplementationByName';
import normalizeError from './normalizeError';

export {
compile,
getTestId,
getCode,
getPureCode,
getCodeFromBundle,
getCodeFromSass,
getImplementationByName,
normalizeError,
};
2 changes: 1 addition & 1 deletion test/helpers/testLoader.js
@@ -1,7 +1,7 @@
'use strict';

function testLoader(content, sourceMap) {
const result = { content };
const result = { css: content };

if (sourceMap) {
result.sourceMap = sourceMap;
Expand Down
24 changes: 12 additions & 12 deletions test/implementation-option.test.js
Expand Up @@ -8,7 +8,7 @@ import dartSass from 'sass';
import {
compile,
getTestId,
getCode,
getCodeFromBundle,
getImplementationByName,
normalizeError,
} from './helpers';
Expand All @@ -32,9 +32,9 @@ describe('implementation option', () => {
implementation: getImplementationByName(implementationName),
};
const stats = await compile(testId, { loader: { options } });
const { content, sourceMap } = getCode(stats);
const { css, sourceMap } = getCodeFromBundle(stats);

expect(content).toBeDefined();
expect(css).toBeDefined();
expect(sourceMap).toBeUndefined();

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

expect(content).toBeDefined();
expect(css).toBeDefined();
expect(sourceMap).toBeUndefined();

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

getCode(stats);
getCodeFromBundle(stats);
} catch (error) {
expect(normalizeError(error)).toMatchSnapshot();
}
Expand All @@ -97,7 +97,7 @@ describe('implementation option', () => {
try {
const stats = await compile(testId, { loader: { options } });

getCode(stats);
getCodeFromBundle(stats);
} catch (error) {
expect(normalizeError(error)).toMatchSnapshot();
}
Expand All @@ -114,7 +114,7 @@ describe('implementation option', () => {
try {
const stats = await compile(testId, { loader: { options } });

getCode(stats);
getCodeFromBundle(stats);
} catch (error) {
expect(normalizeError(error)).toMatchSnapshot();
}
Expand All @@ -129,7 +129,7 @@ describe('implementation option', () => {
try {
const stats = await compile(testId, { loader: { options } });

getCode(stats);
getCodeFromBundle(stats);
} catch (error) {
expect(normalizeError(error)).toMatchSnapshot();
}
Expand All @@ -144,7 +144,7 @@ describe('implementation option', () => {
try {
const stats = await compile(testId, { loader: { options } });

getCode(stats);
getCodeFromBundle(stats);
} catch (error) {
expect(normalizeError(error)).toMatchSnapshot();
}
Expand All @@ -160,7 +160,7 @@ describe('implementation option', () => {
try {
const stats = await compile(testId, { loader: { options } });

getCode(stats);
getCodeFromBundle(stats);
} catch (error) {
expect(normalizeError(error)).toMatchSnapshot();
}
Expand Down Expand Up @@ -191,7 +191,7 @@ describe('implementation option', () => {
try {
const stats = await compile(testId, { loader: { options } });

getCode(stats);
getCodeFromBundle(stats);
} catch (error) {
expect(error).toMatchSnapshot();
}
Expand Down

0 comments on commit dc23895

Please sign in to comment.