-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
272 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
import Dewey from '../dewey'; | ||
import fs from 'fs'; | ||
import { FakeFileObject } from './utils'; | ||
|
||
jest.mock('fs'); | ||
|
||
describe('matching full structure', () => { | ||
beforeAll(() => { | ||
fs.readdirSync.mockImplementation((dirName) => { | ||
switch (dirName) { | ||
case 'dir1': | ||
return ['dir1file1', 'dir1file2', 'dir2', 'dir1ignoreFile', 'dir1ignoreDir']; | ||
case 'dir1/dir2': | ||
return ['dir1dir2file1', 'dir1dir2ignoreFile', 'dir1dir2ignoreDir']; | ||
default: | ||
return ['dir1', 'file1', 'ignoreFile', 'ignoreDir']; | ||
} | ||
}); | ||
}) | ||
|
||
test('Passes when testing a full directory structure using strings', () => { | ||
fs.lstatSync.mockImplementation((name) => new FakeFileObject(name.includes('file') ? false : true)); | ||
const dewey = new Dewey( | ||
'', | ||
{ | ||
ignore: ['ignoreFile', 'ignoreDir'], | ||
files: [{ name: 'file1' }], | ||
dirs: [ | ||
{ | ||
name: 'dir1', | ||
config: { | ||
ignore: ['dir1ignoreFile', 'dir1ignoreDir'], | ||
files: [{ name: 'dir1file1' }, { name: 'dir1file2'}], | ||
dirs: [ | ||
{ | ||
name: 'dir2', | ||
config: { | ||
ignore: ['dir1dir2ignoreFile', 'dir1dir2ignoreDir'], | ||
files: [{ name: 'dir1dir2file1'}] | ||
} | ||
} | ||
] | ||
} | ||
} | ||
] | ||
}, | ||
false, | ||
); | ||
dewey.run(); | ||
}); | ||
|
||
test('Passes when testing a full directory structure using regex', () => { | ||
fs.lstatSync.mockImplementation((name) => new FakeFileObject(name.includes('file') ? false : true)); | ||
const dewey = new Dewey( | ||
'', | ||
{ | ||
ignore: [/ignore[File|Dir]/], | ||
files: [{ name: /file1/ }], | ||
dirs: [ | ||
{ | ||
name: /dir1/, | ||
config: { | ||
ignore: [/dir1ignore[File|Dir]/], | ||
files: [{ name: /dir1file[0-9]/ }], | ||
dirs: [ | ||
{ | ||
name: /dir2/, | ||
config: { | ||
ignore: [/dir1dir2ignore[File|Dir]/], | ||
files: [{ name: /dir1dir2file1/}] | ||
} | ||
} | ||
] | ||
} | ||
} | ||
] | ||
}, | ||
false, | ||
); | ||
dewey.run(); | ||
}); | ||
|
||
test('Passes when testing a full directory structure using functions', () => { | ||
fs.lstatSync.mockImplementation((name) => new FakeFileObject(name.includes('file') ? false : true)); | ||
const dewey = new Dewey( | ||
'', | ||
{ | ||
ignore: [(path, name) => name.includes('ignore')], | ||
files: [{ name: () => 'file1' }], | ||
dirs: [ | ||
{ | ||
name: (path, name) => /dir1/, | ||
config: { | ||
ignore: [(path, name) => name.includes('ignore')], | ||
files: [{ name: (path) => new RegExp(`${path[0]}file[0-9]`)}], | ||
dirs: [ | ||
{ | ||
name: () => 'dir2', | ||
config: { | ||
ignore: [(path, name) => name.includes('ignore')], | ||
files: [{ name: (path) => `${path[1]}${path[0]}file1` }] | ||
} | ||
} | ||
] | ||
} | ||
} | ||
] | ||
}, | ||
false, | ||
); | ||
dewey.run(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import Dewey from '../dewey'; | ||
import fs from 'fs'; | ||
import { FakeFileObject } from './utils'; | ||
|
||
jest.mock('fs'); | ||
|
||
describe('matching regex names', () => { | ||
beforeAll(() => { | ||
fs.readdirSync.mockImplementation(() => ['test1', 'test2']); | ||
}) | ||
|
||
test('Passes with regex file names in objectForm', () => { | ||
fs.lstatSync.mockImplementation(() => new FakeFileObject(false)); | ||
const dewey = new Dewey( | ||
'', | ||
{ files: [{ name: /test1/ }, { name: /test2/ }] }, | ||
false, | ||
); | ||
dewey.run(); | ||
}); | ||
|
||
test('Passes with regex file names in list form', () => { | ||
fs.lstatSync.mockImplementation(() => new FakeFileObject(false)); | ||
const dewey = new Dewey( | ||
'', | ||
{ files: [/test1/, /test2/] }, | ||
false, | ||
); | ||
dewey.run(); | ||
}); | ||
|
||
test('Passes with multiple regex matches', () => { | ||
fs.lstatSync.mockImplementation(() => new FakeFileObject(false)); | ||
const dewey = new Dewey( | ||
'', | ||
{ files: [{ name: /test[0-9]/ }] }, | ||
false, | ||
); | ||
dewey.run(); | ||
}); | ||
|
||
test('Passes with regex file names ignored', () => { | ||
fs.lstatSync.mockImplementation(() => new FakeFileObject(false)); | ||
const dewey = new Dewey( | ||
'', | ||
{ ignore: [/test1/, /test2/] }, | ||
false, | ||
); | ||
dewey.run(); | ||
}); | ||
|
||
test('Passes with string dir names', () => { | ||
fs.lstatSync.mockImplementation(() => new FakeFileObject(true)); | ||
const dewey = new Dewey( | ||
'', | ||
{ dirs: [{ name: /test1/ }, { name: /test2/ }] }, | ||
false, | ||
); | ||
dewey.run(); | ||
}); | ||
|
||
test('Passes with regex dir names ignored', () => { | ||
fs.lstatSync.mockImplementation(() => new FakeFileObject(true)); | ||
const dewey = new Dewey( | ||
'', | ||
{ ignore: [/test1/, /test2/] }, | ||
false, | ||
); | ||
dewey.run(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import Dewey from '../dewey'; | ||
import fs from 'fs'; | ||
import { FakeFileObject } from './utils'; | ||
|
||
jest.mock('fs'); | ||
|
||
describe('matching string names', () => { | ||
beforeAll(() => { | ||
fs.readdirSync.mockImplementation(() => ['test1', 'test2']); | ||
}) | ||
|
||
test('Passes with string file names in objectForm', () => { | ||
fs.lstatSync.mockImplementation(() => new FakeFileObject(false)); | ||
const dewey = new Dewey( | ||
'', | ||
{ files: [{ name: 'test1' }, { name: 'test2' }] }, | ||
false, | ||
); | ||
dewey.run(); | ||
}); | ||
|
||
test('Passes with string file names in list form', () => { | ||
fs.lstatSync.mockImplementation(() => new FakeFileObject(false)); | ||
const dewey = new Dewey( | ||
'', | ||
{ files: ['test1', 'test2'] }, | ||
false, | ||
); | ||
dewey.run(); | ||
}); | ||
|
||
test('Passes with string file names ignored', () => { | ||
fs.lstatSync.mockImplementation(() => new FakeFileObject(false)); | ||
const dewey = new Dewey( | ||
'', | ||
{ ignore: ['test1', 'test2'] }, | ||
false, | ||
); | ||
dewey.run(); | ||
}); | ||
|
||
test('Passes with string dir names', () => { | ||
fs.lstatSync.mockImplementation(() => new FakeFileObject(true)); | ||
const dewey = new Dewey( | ||
'', | ||
{ dirs: [{ name: 'test1' }, { name: 'test2' }] }, | ||
false, | ||
); | ||
dewey.run(); | ||
}); | ||
|
||
test('Passes with string dir names ignored', () => { | ||
fs.lstatSync.mockImplementation(() => new FakeFileObject(true)); | ||
const dewey = new Dewey( | ||
'', | ||
{ ignore: ['test1', 'test2'] }, | ||
false, | ||
); | ||
dewey.run(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
class FakeFileObject { | ||
constructor(isDir) { | ||
this.isDir = isDir; | ||
} | ||
|
||
isFile() { | ||
return !this.isDir; | ||
} | ||
|
||
isDirectory() { | ||
return this.isDir; | ||
} | ||
} | ||
|
||
export { | ||
FakeFileObject, | ||
}; |