From 82be127d069765feefb08524401a193b4777d909 Mon Sep 17 00:00:00 2001 From: evilebottnawi Date: Fri, 16 Aug 2019 17:15:01 +0300 Subject: [PATCH] refactor: code --- .../{getCode.js => getCodeFromBundle.js} | 4 +- .../{getPureCode.js => getCodeFromSass.js} | 8 +- test/helpers/index.js | 8 +- test/helpers/testLoader.js | 2 +- test/implementation-option.test.js | 24 ++-- test/loader.test.js | 134 +++++++++++++----- test/sourceMap-options.test.js | 14 +- 7 files changed, 128 insertions(+), 66 deletions(-) rename test/helpers/{getCode.js => getCodeFromBundle.js} (84%) rename test/helpers/{getPureCode.js => getCodeFromSass.js} (98%) diff --git a/test/helpers/getCode.js b/test/helpers/getCodeFromBundle.js similarity index 84% rename from test/helpers/getCode.js rename to test/helpers/getCodeFromBundle.js index dd2aa2a1..d550d81f 100644 --- a/test/helpers/getCode.js +++ b/test/helpers/getCodeFromBundle.js @@ -1,6 +1,6 @@ const vm = require('vm'); -function getCode(stats, assetName) { +function getCodeFromBundle(stats, assetName) { let code = null; if ( @@ -23,4 +23,4 @@ function getCode(stats, assetName) { return result.default; } -export default getCode; +export default getCodeFromBundle; diff --git a/test/helpers/getPureCode.js b/test/helpers/getCodeFromSass.js similarity index 98% rename from test/helpers/getPureCode.js rename to test/helpers/getCodeFromSass.js index 226e08dc..eb2910f2 100644 --- a/test/helpers/getPureCode.js +++ b/test/helpers/getCodeFromSass.js @@ -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; @@ -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; diff --git a/test/helpers/index.js b/test/helpers/index.js index e7d3bcdf..55ea6dff 100644 --- a/test/helpers/index.js +++ b/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, }; diff --git a/test/helpers/testLoader.js b/test/helpers/testLoader.js index e6cd7f92..45688882 100644 --- a/test/helpers/testLoader.js +++ b/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; diff --git a/test/implementation-option.test.js b/test/implementation-option.test.js index e02aa788..839ba822 100644 --- a/test/implementation-option.test.js +++ b/test/implementation-option.test.js @@ -8,7 +8,7 @@ import dartSass from 'sass'; import { compile, getTestId, - getCode, + getCodeFromBundle, getImplementationByName, normalizeError, } from './helpers'; @@ -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'); @@ -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'); @@ -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(); } @@ -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(); } @@ -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(); } @@ -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(); } @@ -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(); } @@ -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(); } @@ -191,7 +191,7 @@ describe('implementation option', () => { try { const stats = await compile(testId, { loader: { options } }); - getCode(stats); + getCodeFromBundle(stats); } catch (error) { expect(error).toMatchSnapshot(); } diff --git a/test/loader.test.js b/test/loader.test.js index 63f14c88..872cd4ef 100644 --- a/test/loader.test.js +++ b/test/loader.test.js @@ -9,8 +9,8 @@ import dartSass from 'sass'; import { compile, getTestId, - getCode, - getPureCode, + getCodeFromBundle, + getCodeFromSass, getImplementationByName, normalizeError, } from './helpers'; @@ -33,7 +33,9 @@ describe('loader', () => { }; const stats = await compile(testId, { loader: { options } }); - expect(getCode(stats).content).toBe(getPureCode(testId, options)); + expect(getCodeFromBundle(stats).css).toBe( + getCodeFromSass(testId, options).css + ); expect(stats.compilation.warnings).toMatchSnapshot('warnings'); expect(stats.compilation.errors).toMatchSnapshot('errors'); @@ -47,7 +49,9 @@ describe('loader', () => { }; const stats = await compile(testId, { loader: { options } }); - expect(getCode(stats).content).toBe(getPureCode(testId, options)); + expect(getCodeFromBundle(stats).css).toBe( + getCodeFromSass(testId, options).css + ); expect(stats.compilation.warnings).toMatchSnapshot('warnings'); expect(stats.compilation.errors).toMatchSnapshot('errors'); @@ -61,7 +65,9 @@ describe('loader', () => { }; const stats = await compile(testId, { loader: { options } }); - expect(getCode(stats).content).toBe(getPureCode(testId, options)); + expect(getCodeFromBundle(stats).css).toBe( + getCodeFromSass(testId, options).css + ); expect(stats.compilation.warnings).toMatchSnapshot('warnings'); expect(stats.compilation.errors).toMatchSnapshot('errors'); @@ -75,7 +81,9 @@ describe('loader', () => { }; const stats = await compile(testId, { loader: { options } }); - expect(getCode(stats).content).toBe(getPureCode(testId, options)); + expect(getCodeFromBundle(stats).css).toBe( + getCodeFromSass(testId, options).css + ); expect(stats.compilation.warnings).toMatchSnapshot('warnings'); expect(stats.compilation.errors).toMatchSnapshot('errors'); @@ -93,7 +101,9 @@ describe('loader', () => { }; const stats = await compile(testId, { loader: { options } }); - expect(getCode(stats).content).toBe(getPureCode(testId, options)); + expect(getCodeFromBundle(stats).css).toBe( + getCodeFromSass(testId, options).css + ); expect(stats.compilation.warnings).toMatchSnapshot('warnings'); expect(stats.compilation.errors).toMatchSnapshot('errors'); @@ -107,7 +117,9 @@ describe('loader', () => { }; const stats = await compile(testId, { loader: { options } }); - expect(getCode(stats).content).toBe(getPureCode(testId, options)); + expect(getCodeFromBundle(stats).css).toBe( + getCodeFromSass(testId, options).css + ); expect(stats.compilation.warnings).toMatchSnapshot('warnings'); expect(stats.compilation.errors).toMatchSnapshot('errors'); @@ -125,7 +137,9 @@ describe('loader', () => { }; const stats = await compile(testId, { loader: { options } }); - expect(getCode(stats).content).toBe(getPureCode(testId, options)); + expect(getCodeFromBundle(stats).css).toBe( + getCodeFromSass(testId, options).css + ); expect(stats.compilation.warnings).toMatchSnapshot('warnings'); expect(stats.compilation.errors).toMatchSnapshot('errors'); @@ -139,7 +153,9 @@ describe('loader', () => { }; const stats = await compile(testId, { loader: { options } }); - expect(getCode(stats).content).toBe(getPureCode(testId, options)); + expect(getCodeFromBundle(stats).css).toBe( + getCodeFromSass(testId, options).css + ); expect(stats.compilation.warnings).toMatchSnapshot('warnings'); expect(stats.compilation.errors).toMatchSnapshot('errors'); @@ -153,7 +169,9 @@ describe('loader', () => { }; const stats = await compile(testId, { loader: { options } }); - expect(getCode(stats).content).toBe(getPureCode(testId, options)); + expect(getCodeFromBundle(stats).css).toBe( + getCodeFromSass(testId, options).css + ); expect(stats.compilation.warnings).toMatchSnapshot('warnings'); expect(stats.compilation.errors).toMatchSnapshot('errors'); @@ -218,7 +236,9 @@ describe('loader', () => { }; const stats = await compile(testId, { loader: { options } }); - expect(getCode(stats).content).toBe(getPureCode(testId, options)); + expect(getCodeFromBundle(stats).css).toBe( + getCodeFromSass(testId, options).css + ); expect(stats.compilation.warnings).toMatchSnapshot('warnings'); expect(stats.compilation.errors).toMatchSnapshot('errors'); @@ -232,7 +252,9 @@ describe('loader', () => { }; const stats = await compile(testId, { loader: { options } }); - expect(getCode(stats).content).toBe(getPureCode(testId, options)); + expect(getCodeFromBundle(stats).css).toBe( + getCodeFromSass(testId, options).css + ); expect(stats.compilation.warnings).toMatchSnapshot('warnings'); expect(stats.compilation.errors).toMatchSnapshot('errors'); @@ -246,7 +268,9 @@ describe('loader', () => { }; const stats = await compile(testId, { loader: { options } }); - expect(getCode(stats).content).toBe(getPureCode(testId, options)); + expect(getCodeFromBundle(stats).css).toBe( + getCodeFromSass(testId, options).css + ); expect(stats.compilation.warnings).toMatchSnapshot('warnings'); expect(stats.compilation.errors).toMatchSnapshot('errors'); @@ -259,7 +283,9 @@ describe('loader', () => { }; const stats = await compile(testId, { loader: { options } }); - expect(getCode(stats).content).toBe(getPureCode(testId, options)); + expect(getCodeFromBundle(stats).css).toBe( + getCodeFromSass(testId, options).css + ); expect(stats.compilation.warnings).toMatchSnapshot('warnings'); expect(stats.compilation.errors).toMatchSnapshot('errors'); @@ -272,7 +298,9 @@ describe('loader', () => { }; const stats = await compile(testId, { loader: { options } }); - expect(getCode(stats).content).toBe(getPureCode(testId, options)); + expect(getCodeFromBundle(stats).css).toBe( + getCodeFromSass(testId, options).css + ); expect(stats.compilation.warnings).toMatchSnapshot('warnings'); expect(stats.compilation.errors).toMatchSnapshot('errors'); @@ -285,7 +313,9 @@ describe('loader', () => { }; const stats = await compile(testId, { loader: { options } }); - expect(getCode(stats).content).toBe(getPureCode(testId, options)); + expect(getCodeFromBundle(stats).css).toBe( + getCodeFromSass(testId, options).css + ); expect(stats.compilation.warnings).toMatchSnapshot('warnings'); expect(stats.compilation.errors).toMatchSnapshot('errors'); @@ -301,7 +331,9 @@ describe('loader', () => { }; const stats = await compile(testId, { loader: { options } }); - expect(getCode(stats).content).toBe(getPureCode(testId, options)); + expect(getCodeFromBundle(stats).css).toBe( + getCodeFromSass(testId, options).css + ); expect(stats.compilation.warnings).toMatchSnapshot('warnings'); expect(stats.compilation.errors).toMatchSnapshot('errors'); @@ -314,7 +346,9 @@ describe('loader', () => { }; const stats = await compile(testId, { loader: { options } }); - expect(getCode(stats).content).toBe(getPureCode(testId, options)); + expect(getCodeFromBundle(stats).css).toBe( + getCodeFromSass(testId, options).css + ); expect(stats.compilation.warnings).toMatchSnapshot('warnings'); expect(stats.compilation.errors).toMatchSnapshot('errors'); @@ -327,7 +361,9 @@ describe('loader', () => { }; const stats = await compile(testId, { loader: { options } }); - expect(getCode(stats).content).toBe(getPureCode(testId, options)); + expect(getCodeFromBundle(stats).css).toBe( + getCodeFromSass(testId, options).css + ); expect(stats.compilation.warnings).toMatchSnapshot('warnings'); expect(stats.compilation.errors).toMatchSnapshot('errors'); @@ -340,7 +376,9 @@ describe('loader', () => { }; const stats = await compile(testId, { loader: { options } }); - expect(getCode(stats).content).toBe(getPureCode(testId, options)); + expect(getCodeFromBundle(stats).css).toBe( + getCodeFromSass(testId, options).css + ); expect(stats.compilation.warnings).toMatchSnapshot('warnings'); expect(stats.compilation.errors).toMatchSnapshot('errors'); @@ -355,7 +393,9 @@ describe('loader', () => { loader: { options, resolve: { mainFields: [] } }, }); - expect(getCode(stats).content).toBe(getPureCode(testId, options)); + expect(getCodeFromBundle(stats).css).toBe( + getCodeFromSass(testId, options).css + ); expect(stats.compilation.warnings).toMatchSnapshot('warnings'); expect(stats.compilation.errors).toMatchSnapshot('errors'); @@ -370,7 +410,9 @@ describe('loader', () => { loader: { options, resolve: { mainFields: ['main', '...'] } }, }); - expect(getCode(stats).content).toBe(getPureCode(testId, options)); + expect(getCodeFromBundle(stats).css).toBe( + getCodeFromSass(testId, options).css + ); expect(stats.compilation.warnings).toMatchSnapshot('warnings'); expect(stats.compilation.errors).toMatchSnapshot('errors'); @@ -385,7 +427,9 @@ describe('loader', () => { loader: { options, resolve: { mainFields: ['custom-sass', '...'] } }, }); - expect(getCode(stats).content).toBe(getPureCode(testId, options)); + expect(getCodeFromBundle(stats).css).toBe( + getCodeFromSass(testId, options).css + ); expect(stats.compilation.warnings).toMatchSnapshot('warnings'); expect(stats.compilation.errors).toMatchSnapshot('errors'); @@ -398,7 +442,9 @@ describe('loader', () => { }; const stats = await compile(testId, { loader: { options } }); - expect(getCode(stats).content).toBe(getPureCode(testId, options)); + expect(getCodeFromBundle(stats).css).toBe( + getCodeFromSass(testId, options).css + ); expect(stats.compilation.warnings).toMatchSnapshot('warnings'); expect(stats.compilation.errors).toMatchSnapshot('errors'); @@ -413,7 +459,9 @@ describe('loader', () => { loader: { options, resolve: { mainFiles: [] } }, }); - expect(getCode(stats).content).toBe(getPureCode(testId, options)); + expect(getCodeFromBundle(stats).css).toBe( + getCodeFromSass(testId, options).css + ); expect(stats.compilation.warnings).toMatchSnapshot('warnings'); expect(stats.compilation.errors).toMatchSnapshot('errors'); @@ -428,7 +476,9 @@ describe('loader', () => { loader: { options, resolve: { mainFiles: ['index', '...'] } }, }); - expect(getCode(stats).content).toBe(getPureCode(testId, options)); + expect(getCodeFromBundle(stats).css).toBe( + getCodeFromSass(testId, options).css + ); expect(stats.compilation.warnings).toMatchSnapshot('warnings'); expect(stats.compilation.errors).toMatchSnapshot('errors'); @@ -441,7 +491,9 @@ describe('loader', () => { }; const stats = await compile(testId, { loader: { options } }); - expect(getCode(stats).content).toBe(getPureCode(testId, options)); + expect(getCodeFromBundle(stats).css).toBe( + getCodeFromSass(testId, options).css + ); expect(stats.compilation.warnings).toMatchSnapshot('warnings'); expect(stats.compilation.errors).toMatchSnapshot('errors'); @@ -456,7 +508,9 @@ describe('loader', () => { }; const stats = await compile(testId, { loader: { options } }); - expect(getCode(stats).content).toBe(getPureCode(testId, options)); + expect(getCodeFromBundle(stats).css).toBe( + getCodeFromSass(testId, options).css + ); expect(stats.compilation.warnings).toMatchSnapshot('warnings'); expect(stats.compilation.errors).toMatchSnapshot('errors'); @@ -481,7 +535,9 @@ describe('loader', () => { loader: { options }, }); - expect(getCode(stats).content).toBe(getPureCode(testId, options)); + expect(getCodeFromBundle(stats).css).toBe( + getCodeFromSass(testId, options).css + ); expect(stats.compilation.warnings).toMatchSnapshot('warnings'); expect(stats.compilation.errors).toMatchSnapshot('errors'); @@ -494,7 +550,9 @@ describe('loader', () => { }; const stats = await compile(testId, { loader: { options } }); - expect(getCode(stats).content).toBe(getPureCode(testId, options)); + expect(getCodeFromBundle(stats).css).toBe( + getCodeFromSass(testId, options).css + ); expect(stats.compilation.warnings).toMatchSnapshot('warnings'); expect(stats.compilation.errors).toMatchSnapshot('errors'); @@ -507,7 +565,9 @@ describe('loader', () => { }; const stats = await compile(testId, { loader: { options } }); - expect(getCode(stats).content).toBe(getPureCode(testId, options)); + expect(getCodeFromBundle(stats).css).toBe( + getCodeFromSass(testId, options).css + ); expect(stats.compilation.warnings).toMatchSnapshot('warnings'); expect(stats.compilation.errors).toMatchSnapshot('errors'); @@ -520,7 +580,9 @@ describe('loader', () => { }; const stats = await compile(testId, { loader: { options } }); - expect(getCode(stats).content).toBe(getPureCode(testId, options)); + expect(getCodeFromBundle(stats).css).toBe( + getCodeFromSass(testId, options).css + ); expect(stats.compilation.warnings).toMatchSnapshot('warnings'); expect(stats.compilation.errors).toMatchSnapshot('errors'); @@ -536,13 +598,13 @@ describe('loader', () => { loader: { options }, }); - expect(getCode(stats).content).toBe( - getPureCode( + expect(getCodeFromBundle(stats).css).toBe( + getCodeFromSass( testId, Object.assign({}, options, { outputStyle: 'compressed', }) - ) + ).css ); expect(stats.compilation.warnings).toMatchSnapshot('warnings'); diff --git a/test/sourceMap-options.test.js b/test/sourceMap-options.test.js index 6513f7ee..8b4a94c8 100644 --- a/test/sourceMap-options.test.js +++ b/test/sourceMap-options.test.js @@ -10,7 +10,7 @@ import dartSass from 'sass'; import { compile, getTestId, - getCode, + getCodeFromBundle, getImplementationByName, } from './helpers'; @@ -30,9 +30,9 @@ describe('sourceMap option', () => { sourceMap: undefined, }; 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'); @@ -46,9 +46,9 @@ describe('sourceMap option', () => { sourceMap: false, }; 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'); @@ -64,9 +64,9 @@ describe('sourceMap option', () => { sourceMap: true, }; 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).toBeDefined(); expect(sourceMap.file).toBeUndefined();