How to use the clean-css.prototype function in clean-css

To help you get started, we’ve selected a few clean-css examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github puzzle-js / puzzle-js / tests / resource-injector.spec.ts View on Github external
it("should inject style sheets using default version", async (done) => {

        // arrange
        const fragments = {
            "f1": FragmentHelper.create(),
            "f2": FragmentHelper.create()
        };

        sandbox.stub(fragments.f1, "getAsset").callsFake((arg) => arg + "-CSS-");
        sandbox.stub(fragments.f2, "getAsset").callsFake((arg) => arg + "-CSS-");
        sandbox.stub(ResourceFactory.instance, "getRawContent").callsFake( (arg): any => arg + "-CSS-");
        sandbox.stub(CleanCSS.prototype, "minify").callsFake( (arg): any => ({ styles: arg }));

        // act
        const dom = cheerio.load("");
        const resourceInjector = new ResourceInjector(fragments, "", {});
        await resourceInjector.injectStyleSheets(dom as any, false);

        const c1 = fragments.f1.config;
        const c2 = fragments.f2.config;

        const assets = c1.assets.concat(c2.assets).filter((asset) => asset.type === RESOURCE_TYPE.CSS);
        const deps = c1.dependencies.concat(c2.dependencies).filter((dep) => dep.type === RESOURCE_TYPE.CSS);

        let expectedDependencyList = assets.concat(deps).map( (res) => res.name);
        expectedDependencyList = expectedDependencyList.filter((v,i) => expectedDependencyList.indexOf(v) === i); // remove dublications
        const expectedCssContent = expectedDependencyList.concat([""]); // for last -CSS-
github puzzle-js / puzzle-js / tests / resource-injector.spec.ts View on Github external
it("should inject style sheets using passive version", async (done) => {

        // arrange
        const fragments = {
            "f1": FragmentHelper.create(),
            "f2": FragmentHelper.create()
        };

        const f1Version = faker.random.arrayElement(["2.0.0", "3.0.0"]);
        const f2Version = faker.random.arrayElement(["2.0.0", "3.0.0"]);
        sandbox.stub(fragments.f1, "detectVersion").callsFake(() => f1Version);
        sandbox.stub(fragments.f2, "detectVersion").callsFake( () => f2Version);
        sandbox.stub(fragments.f1, "getAsset").callsFake((arg) => arg + "-CSS-");
        sandbox.stub(fragments.f2, "getAsset").callsFake((arg) => arg + "-CSS-");
        sandbox.stub(ResourceFactory.instance, "getRawContent").callsFake( (arg): any => arg + "-CSS-");
        sandbox.stub(CleanCSS.prototype, "minify").callsFake( (arg): any => ({ styles: arg }));

        // act
        const dom = cheerio.load("");
        const resourceInjector = new ResourceInjector(fragments, "", {});
        await resourceInjector.injectStyleSheets(dom as any, false);

        const c1 = fragments.f1.config.passiveVersions[f1Version];
        const c2 = fragments.f2.config.passiveVersions[f2Version];

        const assets = c1.assets.concat(c2.assets).filter((asset) => asset.type === RESOURCE_TYPE.CSS);
        const deps = c1.dependencies.concat(c2.dependencies).filter((dep) => dep.type === RESOURCE_TYPE.CSS);

        const expectedDependencyList = assets.concat(deps).map( (res) => res.name);
        const expectedCssContent = expectedDependencyList.concat([""]); // for last -CSS-

        // assert

clean-css

A well-tested CSS minifier

MIT
Latest version published 11 months ago

Package Health Score

91 / 100
Full package analysis