Skip to content

Commit

Permalink
Finally fix test and coverage issues.
Browse files Browse the repository at this point in the history
  • Loading branch information
dhkatz committed Aug 23, 2019
1 parent ef352d1 commit 44c507b
Show file tree
Hide file tree
Showing 6 changed files with 205 additions and 260 deletions.
228 changes: 63 additions & 165 deletions lib/index.js

Large diffs are not rendered by default.

122 changes: 80 additions & 42 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

58 changes: 27 additions & 31 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@
"name": "gulp-filename",
"version": "5.0.1",
"description": "Register every filename that has passed through",
"files": ["lib/", "typings/", "test/"],
"main": "lib/index.js",
"files": [
"lib/",
"typings/",
"test/"
],
"types": "typings/index.d.ts",
"keywords": [
"gulpplugin"
Expand All @@ -26,7 +31,7 @@
"scripts": {
"build": "npm run build:types && npm run build:js",
"build:types": "tsc --emitDeclarationOnly",
"build:js": "babel src --out-dir lib --extensions \".ts,.tsx\" --source-maps inline",
"build:js": "tsc",
"lint": "eslint src/**/* && tsc --noEmit",
"test": "jest --ci --verbose --forceExit --detectOpenHandles",
"test:coverage": "jest --coverage --ci",
Expand All @@ -45,49 +50,40 @@
"@types/node": "^12.0.4",
"@types/through2": "^2.0.34",
"@types/vinyl": "^2.0.3",
"@types/vinyl-source-stream": "0.0.30",
"@typescript-eslint/eslint-plugin": "^1.9.0",
"@typescript-eslint/parser": "^1.9.0",
"coveralls": "^3.0.3",
"eslint": "^5.16.0",
"gulp": "^4.0.2",
"jest": "^24.8.0",
"ts-jest": "^24.0.2",
"typescript": "^3.5.1",
"vinyl": "^2.2.0",
"vinyl-source-stream": "^2.0.0"
},
"babel": {
"presets": [
[
"@babel/env",
{
"useBuiltIns": "entry",
"corejs": "3"
}
],
"@babel/typescript"
],
"plugins": [
[
"@babel/proposal-class-properties",
{
"loose": true
}
],
"@babel/proposal-object-rest-spread"
],
"sourceMaps": "inline"
},
"jest": {
"roots": [
"<rootDir>/test"
],
"testRegex": "(/test/.*|(\\.|/)(test|spec))\\.(tsx?)$",
"collectCoverage": true,
"transform": {
".(ts|tsx)": "ts-jest"
},
"testEnvironment": "node",
"moduleNameMapper": {
"^@/(.*)$": "<rootDir>/src/$1"
"testRegex": "(/__tests__/.*|\\.(test|spec))\\.(ts|tsx|js)$",
"moduleFileExtensions": [
"ts",
"tsx",
"js"
],
"coverageThreshold": {
"global": {
"branches": 90,
"functions": 95,
"lines": 95,
"statements": 95
}
},
"collectCoverageFrom": [
"<rootDir>/src/**/*.{ts,tsx}"
"src/*.{js,ts}"
]
},
"eslintConfig": {
Expand Down
5 changes: 3 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export class Filenames extends Function {

public constructor() {
super();

return new Proxy(this, {
// eslint-disable-next-line
apply: (target: this, thisArg: this, args: any[]): any => {
Expand Down Expand Up @@ -62,6 +62,7 @@ export class Filenames extends Function {
public get(name: 'all' | string | symbol = this.DEFAULT, type: PathType = 'relative'): Map<string | symbol, File[]> | string[] | File[] {
if (typeof name === 'string' && name === 'all') return this.names;

/* istanbul ignore next */
if (!this.names.has(name)) this.names.set(name, []);

const files = this.names.get(name);
Expand Down Expand Up @@ -92,7 +93,7 @@ export class Filenames extends Function {
}

public register(file: vinyl.StreamFile, name: string | symbol = this.DEFAULT, options: Options = { override: false }): void {
if (options.override || !this.names.has(name)) {
if (options.override || !this.names.has(name)) {
this.names.set(name, []);
}

Expand Down
31 changes: 23 additions & 8 deletions test/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { createReadStream } from 'fs';
import { isAbsolute } from 'path';
import { src, dest } from 'gulp';
import { Transform } from 'stream';
import source from 'vinyl-source-stream';

import filenames from '../lib';
import filenames from '../src';


describe('gulp-filesnames', (): void => {
describe('gulp-filename', (): void => {
afterEach((): void => {
filenames.forget('all');
});
Expand All @@ -16,7 +17,7 @@ describe('gulp-filesnames', (): void => {
.pipe(filenames())
.pipe(dest('.temp/'))
.on('end', (): void => {
expect(filenames.get()).toEqual(['a.cc', 'a.empty', 'a.txt','b.txt']);
expect(filenames.get()).toEqual(['a.cc', 'a.empty', 'a.txt', 'b.txt']);

done();
});
Expand All @@ -28,7 +29,7 @@ describe('gulp-filesnames', (): void => {
.pipe(dest('.temp/'))
.on('end', (): void => {
filenames.get(filenames.DEFAULT, 'absolute').forEach((file: string): void => {
expect(file.includes('test/files/')).toBeTruthy();
expect(isAbsolute(file)).toBeTruthy();
});

done();
Expand All @@ -41,8 +42,7 @@ describe('gulp-filesnames', (): void => {
.pipe(dest('.temp/'))
.on('end', (): void => {
filenames.get(filenames.DEFAULT, 'base').forEach((file: string): void => {
console.log(file);
expect(file.includes('test/files')).toBeTruthy();
expect(isAbsolute(file)).toBeTruthy();
});

done();
Expand Down Expand Up @@ -92,7 +92,7 @@ describe('gulp-filesnames', (): void => {
.pipe(filenames('override'))
.pipe(dest('.temp/'))
.on('end', (): void => {
expect(filenames.get('override')).toEqual(['a.cc', 'a.empty', 'a.txt','b.txt']);
expect(filenames.get('override')).toEqual(['a.cc', 'a.empty', 'a.txt', 'b.txt']);

src('test/files/**/*.txt')
.pipe(filenames('override', { override: true }))
Expand Down Expand Up @@ -127,7 +127,7 @@ describe('gulp-filesnames', (): void => {
.pipe(filenames('default'))
.pipe(dest('.temp/'))
.on('end', (): void => {
expect(filenames.get('default')).toEqual(['a.cc', 'a.empty', 'a.txt','b.txt']);
expect(filenames.get('default')).toEqual(['a.cc', 'a.empty', 'a.txt', 'b.txt']);

done();
});
Expand All @@ -144,4 +144,19 @@ describe('gulp-filesnames', (): void => {
done();
});
});

it('Should allow retrieving the all namespace', (done): void => {
src('test/files/**/*.*')
.pipe(filenames())
.pipe(dest('.temp/'))
.on('end', (): void => {
const names = filenames.get('all');

expect(names).toBeInstanceOf(Map);
expect(names.size).toBe(1);
expect(names.get(filenames.DEFAULT).length).toBe(4);

done();
});
});
});
Loading

0 comments on commit 44c507b

Please sign in to comment.