Skip to content

Commit

Permalink
fix(gulp-purgecss): fix support for stream input
Browse files Browse the repository at this point in the history
  • Loading branch information
Ffloriel committed Nov 26, 2021
1 parent 365fb60 commit fd5d3bf
Show file tree
Hide file tree
Showing 11 changed files with 1,934 additions and 1,422 deletions.
2 changes: 1 addition & 1 deletion jest.config.js
Expand Up @@ -2,7 +2,7 @@ module.exports = {
preset: "ts-jest",
coverageDirectory: "coverage",
coverageReporters: ["html", "lcov", "text"],
collectCoverageFrom: ["packages/*/src/**/*.ts"],
collectCoverageFrom: ["packages/*/src/**/*.ts", "!packages/grunt-purgecss/**/*.ts"],
moduleFileExtensions: ["ts", "tsx", "js", "json"],
moduleNameMapper: {
"^purgecss$": "<rootDir>/packages/purgecss/src",
Expand Down
1,511 changes: 833 additions & 678 deletions package-lock.json

Large diffs are not rendered by default.

16 changes: 8 additions & 8 deletions package.json
Expand Up @@ -18,24 +18,24 @@
"@rollup/plugin-json": "^4.1.0",
"@types/jest": "^27.0.2",
"@types/node": "^16.0.0",
"@typescript-eslint/eslint-plugin": "^5.3.0",
"@typescript-eslint/parser": "^5.3.0",
"@typescript-eslint/eslint-plugin": "^5.4.0",
"@typescript-eslint/parser": "^5.4.0",
"@vuepress/plugin-google-analytics": "^1.8.2",
"@vuepress/theme-default": "^1.8.2",
"conventional-changelog-cli": "^2.1.1",
"eslint": "^8.2.0",
"eslint": "^8.3.0",
"husky": "^7.0.1",
"jest": "^27.3.1",
"lerna": "^4.0.0",
"lint-staged": "^11.0.0",
"prettier": "^2.4.1",
"rollup": "^2.59.0",
"lint-staged": "^12.0.0",
"prettier": "^2.5.0",
"rollup": "^2.60.0",
"rollup-plugin-node-resolve": "^5.2.0",
"rollup-plugin-terser": "^7.0.2",
"rollup-plugin-ts": "^1.4.0",
"rollup-plugin-ts": "^2.0.0",
"ts-jest": "^27.0.7",
"ts-node": "^10.4.0",
"typescript": "^4.4.4",
"typescript": "^4.5.2",
"vuepress": "^1.8.2"
},
"scripts": {
Expand Down
50 changes: 50 additions & 0 deletions packages/gulp-purgecss/__tests__/stream.test.ts
@@ -0,0 +1,50 @@
import es from 'event-stream';
import internal, { PassThrough } from "stream";
import File from "vinyl";
import gulpPurgecss from "../src/";

describe("gulp-purgecss with stream", () => {
let myGulpPurgecss: internal.Transform;
let fileTest: File.StreamFile;
let fakeStream: internal.PassThrough;

beforeEach(() => {
fakeStream = new PassThrough();
fakeStream.write(Buffer.from(".unused, .used,"));
fakeStream.write(Buffer.from(" a { color:"));
fakeStream.write(Buffer.from(" blue; }"));
fakeStream.end();
fileTest = new File({
contents: fakeStream,
});
myGulpPurgecss = gulpPurgecss({
content: ["./packages/gulp-purgecss/__tests__/test.html"],
});
});

// it("returns a stream", (done) => {
// expect.assertions(1);
// myGulpPurgecss.write(fileTest);
// myGulpPurgecss.once("data", (file) => {
// expect(file.isStream()).toBe(true);
// done();
// });
// });

it("returns a purged css stream", (done) => {
expect.assertions(3);
myGulpPurgecss.write(fileTest);
myGulpPurgecss.on("data", (file: File.StreamFile) => {
file.contents.pipe(
es.wait((_err: any, data: string) => {
expect(data.includes("used")).toBe(true);
expect(data.includes("unused")).toBe(false);
expect(data.includes("a")).toBe(true);
done();
})
);
});
// myGulpPurgecss.on("end", done);
});

});

0 comments on commit fd5d3bf

Please sign in to comment.