Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: code #725

Merged
merged 1 commit into from Aug 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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