From 2588aca2ddbef04f03e972cd6486ab01d3f5e910 Mon Sep 17 00:00:00 2001 From: Jason English Date: Mon, 27 Aug 2018 09:37:13 -0700 Subject: [PATCH] feat(useable): add `insertInto` support (`options.insertInto`) (#341) --- test/useable.test.js | 142 +++++++++++++++++++++++++++++++++++++------ useable.js | 19 +++++- 2 files changed, 142 insertions(+), 19 deletions(-) diff --git a/test/useable.test.js b/test/useable.test.js index 981da074..0e1a945d 100644 --- a/test/useable.test.js +++ b/test/useable.test.js @@ -8,30 +8,136 @@ var loaderUtils = require('loader-utils'); var useable = require("../useable"); describe("useable tests", function () { - var sandbox = sinon.sandbox.create(); - var getOptions; + describe('hmr', function () { + var sandbox = sinon.sandbox.create(); + var getOptions; - beforeEach(() => { - // Mock loaderUtils to override options - getOptions = sandbox.stub(loaderUtils, 'getOptions'); - }); + beforeEach(() => { + // Mock loaderUtils to override options + getOptions = sandbox.stub(loaderUtils, 'getOptions'); + }); - afterEach(() => { - sandbox.restore(); - }); + afterEach(() => { + sandbox.restore(); + }); - it("should output HMR code by default", function () { - assert.equal(/(module\.hot)/g.test(useable.pitch()), true); - }); + it("should output HMR code by default", function () { + assert.equal(/(module\.hot)/g.test(useable.pitch()), true); + }); - it("should NOT output HMR code when options.hmr is false", function () { - getOptions.returns({hmr: false}); - assert.equal(/(module\.hot)/g.test(useable.pitch()), false); + it("should NOT output HMR code when options.hmr is false", function () { + getOptions.returns({hmr: false}); + assert.equal(/(module\.hot)/g.test(useable.pitch()), false); + }); + + it("should output HMR code when options.hmr is true", function () { + getOptions.returns({hmr: true}); + assert.equal(/(module\.hot)/g.test(useable.pitch()), true); + }); }); - it("should output HMR code when options.hmr is true", function () { - getOptions.returns({hmr: true}); - assert.equal(/(module\.hot)/g.test(useable.pitch()), true); + describe('insert into', function () { + var path = require("path"); + + var utils = require("./utils"), + runCompilerTest = utils.runCompilerTest; + + var fs; + + var requiredCss = ".required { color: blue }", + requiredCssTwo = ".requiredTwo { color: cyan }", + localScopedCss = ":local(.className) { background: red; }", + localComposingCss = ` + :local(.composingClass) { + composes: className from './localScoped.css'; + color: blue; + } + `, + requiredStyle = ``, + existingStyle = ``, + checkValue = '
check
', + rootDir = path.resolve(__dirname + "/../") + "/", + jsdomHtml = [ + "", + "", + existingStyle, + "", + "", + "
", + checkValue, + "
", + "