diff --git a/src/index.js b/src/index.js index 2b6a4f3..63a1058 100644 --- a/src/index.js +++ b/src/index.js @@ -21,7 +21,10 @@ function getScopedNameGenerator(opts) { const scopedNameGenerator = opts.generateScopedName || generateScopedName; if (typeof scopedNameGenerator === "function") return scopedNameGenerator; - return genericNames(scopedNameGenerator, { context: process.cwd() }); + return genericNames(scopedNameGenerator, { + context: process.cwd(), + hashPrefix: opts.hashPrefix + }); } function getLoader(opts, plugins) { diff --git a/test/test.js b/test/test.js index 2939265..1c6efcc 100644 --- a/test/test.js +++ b/test/test.js @@ -112,6 +112,24 @@ it("processes camelCase option", async () => { }); }); +it("processes hashPrefix option", async () => { + const generateScopedName = "[hash:base64:5]"; + const hashPrefix = "prefix"; + const getJSON = () => {}; + + const withoutHashPrefix = plugin({ generateScopedName, getJSON }); + const withHashPrefix = plugin({ generateScopedName, getJSON, hashPrefix }); + + const css = ".foo {}"; + const params = { from: "test.css" }; + + const result1 = await postcss([withoutHashPrefix]).process(css, params); + const result2 = await postcss([withHashPrefix]).process(css, params); + + expect(result2.css).toMatchSnapshot("processes hashPrefix option"); + expect(result1.css).not.toEqual(result2.css); +}); + it("different instances have different generateScopedName functions", async () => { const one = plugin({ generateScopedName: () => "one",