Skip to content
This repository has been archived by the owner on Jan 3, 2024. It is now read-only.

Commit

Permalink
fix: Read files even if they have a leading dot (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
stephan-noel authored Jul 27, 2020
1 parent 57dc1a8 commit 3f04be0
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 5 deletions.
Empty file.
66 changes: 66 additions & 0 deletions core/garment/__tests__/garment.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import { executeRunner2, initFixtureHelper } from '@garment/fixture-helper';
import * as Path from 'path';
import { createFileInput } from '../src';

const { initFixture, clean } = initFixtureHelper(module, {
tempDir: Path.join(__dirname, '/tmp__')
});

afterAll(clean);

describe('createFileInput', () => {
test('It does basic glob pattern matching', async () => {
const includedExtension = '.js';
const excludedName = 'exclude-me';

const testDir = await initFixture('basic', {
files: {
[`index${includedExtension}`]: 'mock content',
[`some-name-${excludedName}-file${includedExtension}`]: 'mock content',
'something.html': 'mock content'
}
});

const input = createFileInput({
rootDir: testDir,
include: [`*${includedExtension}`],
exclude: [`*${excludedName}*`]
});

let filesCount = 0;
for (let file of input) {
const { name, ext } = Path.parse(file.path);
expect(ext).toBe(includedExtension);
expect(name).not.toContain(excludedName);

filesCount++;
}

expect(filesCount).toBe(1);
});

test('glob pattern matching includes files whose names begin with a dot', async () => {
const testDir = await initFixture('basic', {
files: {
'.gitignore': 'mock content',
'.npmrc': 'more mock content'
}
});

// We need a file in fixtures directory to keep in source control for initFixture
const fixtureKeep = '.gitkeep';
const allFilesGlob = '*';
const input = createFileInput({
rootDir: testDir,
include: [allFilesGlob],
exclude: [fixtureKeep]
});

let filesCount = 0;
for (let file of input) {
filesCount++;
}

expect(filesCount).toBe(2);
});
});
3 changes: 2 additions & 1 deletion core/garment/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
],
"devDependencies": {
"@types/is-valid-path": "^0.1.0",
"@types/tempy": "^0.2.0"
"@types/tempy": "^0.2.0",
"@garment/fixture-helper": "^0.13.8"
}
}
5 changes: 3 additions & 2 deletions core/garment/src/garment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1061,15 +1061,16 @@ async function garmentFromWorkspace(
export default garment;
export { garment, garmentFromWorkspace };

function* createFileInput(
export function* createFileInput(
{ rootDir, files = [], include, exclude = [] }: Input,
fsInstance = fs
) {
const filesFromGlob = include
? globby.sync(include, {
cwd: rootDir,
absolute: true,
ignore: exclude
ignore: exclude,
dot: true
})
: [];
const uniqueFiles = new Set([...files, ...filesFromGlob]);
Expand Down
4 changes: 2 additions & 2 deletions docs/Configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -242,11 +242,11 @@ Defines which files are sent as an input to the runner. If defined as an object,
{
"rootDir": "{{projectDir}}/src",
"include": ["**/*.js"],
"ignore": []
"exclude": []
}
```

`rootDir: string` defines where the input files are. `include: string[]` and `ignore: string[]` define glob patterns to include to or exclude from files set. Note, that each runner can have a default `include` and `ignore` patterns, so the developer only needs to define a `rootDir`. If `input` is a `string` then it defines a `rootDir` and uses default values `[**/*]` for include and `[]` for ignore, or the ones defined by runner.
`rootDir: string` defines where the input files are. `include: string[]` and `exclude: string[]` define glob patterns to include to or exclude from files set. Note, that each runner can have a default `include` and `exclude` patterns, so the developer only needs to define a `rootDir`. If `input` is a `string` then it defines a `rootDir` and uses default values `[**/*]` for include and `[]` for exclude, or the ones defined by runner.

If not specified, the files from previous tasks will be passed as input files. If you want to receive both files from the disk and previous tasks, you should specify `pipe` option as `true` or glob pattern;

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"clean": "yarn gr clean && tsc -b --clean",
"lint": "echo Everything seems good!",
"test": "yarn gr test",
"test-debug": "node --inspect-brk node_modules/@garment/cli/lib/cli.js test --runInBand",
"bump": "lerna version -m 'chore: Release' --conventional-commits",
"bump:pre": "lerna version prerelease --no-git-tag-version --no-push",
"publish": "yarn gr publish",
Expand Down

0 comments on commit 3f04be0

Please sign in to comment.