-
-
Notifications
You must be signed in to change notification settings - Fork 133
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
216 additions
and
124 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
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 |
---|---|---|
@@ -1,101 +1,120 @@ | ||
import path from 'node:path'; | ||
import {fileURLToPath} from 'node:url'; | ||
import {fileURLToPath, pathToFileURL} from 'node:url'; | ||
import test from 'ava'; | ||
import slash from 'slash'; | ||
import {isGitIgnored, isGitIgnoredSync} from './gitignore.js'; | ||
|
||
const __dirname = path.dirname(fileURLToPath(import.meta.url)); | ||
const getCwdValues = cwd => [cwd, pathToFileURL(cwd), pathToFileURL(cwd).href]; | ||
|
||
test('gitignore', async t => { | ||
const cwd = path.join(__dirname, 'fixtures/gitignore'); | ||
const isIgnored = await isGitIgnored({cwd}); | ||
const actual = ['foo.js', 'bar.js'].filter(file => !isIgnored(file)); | ||
const expected = ['bar.js']; | ||
t.deepEqual(actual, expected); | ||
for (const cwd of getCwdValues(path.join(__dirname, 'fixtures/gitignore'))) { | ||
// eslint-disable-next-line no-await-in-loop | ||
const isIgnored = await isGitIgnored({cwd}); | ||
const actual = ['foo.js', 'bar.js'].filter(file => !isIgnored(file)); | ||
const expected = ['bar.js']; | ||
t.deepEqual(actual, expected); | ||
} | ||
}); | ||
|
||
test('gitignore - mixed path styles', async t => { | ||
const cwd = path.join(__dirname, 'fixtures/gitignore'); | ||
const isIgnored = await isGitIgnored({cwd}); | ||
t.true(isIgnored(slash(path.resolve(cwd, 'foo.js')))); | ||
const directory = path.join(__dirname, 'fixtures/gitignore'); | ||
for (const cwd of getCwdValues(directory)) { | ||
// eslint-disable-next-line no-await-in-loop | ||
const isIgnored = await isGitIgnored({cwd}); | ||
t.true(isIgnored(slash(path.resolve(directory, 'foo.js')))); | ||
} | ||
}); | ||
|
||
test('gitignore - os paths', async t => { | ||
const cwd = path.join(__dirname, 'fixtures/gitignore'); | ||
const isIgnored = await isGitIgnored({cwd}); | ||
t.true(isIgnored(path.resolve(cwd, 'foo.js'))); | ||
const directory = path.join(__dirname, 'fixtures/gitignore'); | ||
for (const cwd of getCwdValues(directory)) { | ||
// eslint-disable-next-line no-await-in-loop | ||
const isIgnored = await isGitIgnored({cwd}); | ||
t.true(isIgnored(path.resolve(directory, 'foo.js'))); | ||
} | ||
}); | ||
|
||
test('gitignore - sync', t => { | ||
const cwd = path.join(__dirname, 'fixtures/gitignore'); | ||
const isIgnored = isGitIgnoredSync({cwd}); | ||
const actual = ['foo.js', 'bar.js'].filter(file => !isIgnored(file)); | ||
const expected = ['bar.js']; | ||
t.deepEqual(actual, expected); | ||
for (const cwd of getCwdValues(path.join(__dirname, 'fixtures/gitignore'))) { | ||
const isIgnored = isGitIgnoredSync({cwd}); | ||
const actual = ['foo.js', 'bar.js'].filter(file => !isIgnored(file)); | ||
const expected = ['bar.js']; | ||
t.deepEqual(actual, expected); | ||
} | ||
}); | ||
|
||
test('ignore ignored .gitignore', async t => { | ||
const cwd = path.join(__dirname, 'fixtures/gitignore'); | ||
const ignore = ['**/.gitignore']; | ||
|
||
const isIgnored = await isGitIgnored({cwd, ignore}); | ||
const actual = ['foo.js', 'bar.js'].filter(file => !isIgnored(file)); | ||
const expected = ['foo.js', 'bar.js']; | ||
t.deepEqual(actual, expected); | ||
for (const cwd of getCwdValues(path.join(__dirname, 'fixtures/gitignore'))) { | ||
// eslint-disable-next-line no-await-in-loop | ||
const isIgnored = await isGitIgnored({cwd, ignore}); | ||
const actual = ['foo.js', 'bar.js'].filter(file => !isIgnored(file)); | ||
const expected = ['foo.js', 'bar.js']; | ||
t.deepEqual(actual, expected); | ||
} | ||
}); | ||
|
||
test('ignore ignored .gitignore - sync', t => { | ||
const cwd = path.join(__dirname, 'fixtures/gitignore'); | ||
const ignore = ['**/.gitignore']; | ||
|
||
const isIgnored = isGitIgnoredSync({cwd, ignore}); | ||
const actual = ['foo.js', 'bar.js'].filter(file => !isIgnored(file)); | ||
const expected = ['foo.js', 'bar.js']; | ||
t.deepEqual(actual, expected); | ||
for (const cwd of getCwdValues(path.join(__dirname, 'fixtures/gitignore'))) { | ||
const isIgnored = isGitIgnoredSync({cwd, ignore}); | ||
const actual = ['foo.js', 'bar.js'].filter(file => !isIgnored(file)); | ||
const expected = ['foo.js', 'bar.js']; | ||
t.deepEqual(actual, expected); | ||
} | ||
}); | ||
|
||
test('negative gitignore', async t => { | ||
const cwd = path.join(__dirname, 'fixtures/negative'); | ||
const isIgnored = await isGitIgnored({cwd}); | ||
const actual = ['foo.js', 'bar.js'].filter(file => !isIgnored(file)); | ||
const expected = ['foo.js']; | ||
t.deepEqual(actual, expected); | ||
for (const cwd of getCwdValues(path.join(__dirname, 'fixtures/negative'))) { | ||
// eslint-disable-next-line no-await-in-loop | ||
const isIgnored = await isGitIgnored({cwd}); | ||
const actual = ['foo.js', 'bar.js'].filter(file => !isIgnored(file)); | ||
const expected = ['foo.js']; | ||
t.deepEqual(actual, expected); | ||
} | ||
}); | ||
|
||
test('negative gitignore - sync', t => { | ||
const cwd = path.join(__dirname, 'fixtures/negative'); | ||
const isIgnored = isGitIgnoredSync({cwd}); | ||
const actual = ['foo.js', 'bar.js'].filter(file => !isIgnored(file)); | ||
const expected = ['foo.js']; | ||
t.deepEqual(actual, expected); | ||
for (const cwd of getCwdValues(path.join(__dirname, 'fixtures/negative'))) { | ||
const isIgnored = isGitIgnoredSync({cwd}); | ||
const actual = ['foo.js', 'bar.js'].filter(file => !isIgnored(file)); | ||
const expected = ['foo.js']; | ||
t.deepEqual(actual, expected); | ||
} | ||
}); | ||
|
||
test('multiple negation', async t => { | ||
const cwd = path.join(__dirname, 'fixtures/multiple-negation'); | ||
const isIgnored = await isGitIgnored({cwd}); | ||
|
||
const actual = [ | ||
'!!!unicorn.js', | ||
'!!unicorn.js', | ||
'!unicorn.js', | ||
'unicorn.js', | ||
].filter(file => !isIgnored(file)); | ||
|
||
const expected = ['!!unicorn.js', '!unicorn.js']; | ||
t.deepEqual(actual, expected); | ||
for (const cwd of getCwdValues(path.join(__dirname, 'fixtures/multiple-negation'))) { | ||
// eslint-disable-next-line no-await-in-loop | ||
const isIgnored = await isGitIgnored({cwd}); | ||
|
||
const actual = [ | ||
'!!!unicorn.js', | ||
'!!unicorn.js', | ||
'!unicorn.js', | ||
'unicorn.js', | ||
].filter(file => !isIgnored(file)); | ||
|
||
const expected = ['!!unicorn.js', '!unicorn.js']; | ||
t.deepEqual(actual, expected); | ||
} | ||
}); | ||
|
||
test('multiple negation - sync', t => { | ||
const cwd = path.join(__dirname, 'fixtures/multiple-negation'); | ||
const isIgnored = isGitIgnoredSync({cwd}); | ||
|
||
const actual = [ | ||
'!!!unicorn.js', | ||
'!!unicorn.js', | ||
'!unicorn.js', | ||
'unicorn.js', | ||
].filter(file => !isIgnored(file)); | ||
|
||
const expected = ['!!unicorn.js', '!unicorn.js']; | ||
t.deepEqual(actual, expected); | ||
for (const cwd of getCwdValues(path.join(__dirname, 'fixtures/multiple-negation'))) { | ||
const isIgnored = isGitIgnoredSync({cwd}); | ||
|
||
const actual = [ | ||
'!!!unicorn.js', | ||
'!!unicorn.js', | ||
'!unicorn.js', | ||
'unicorn.js', | ||
].filter(file => !isIgnored(file)); | ||
|
||
const expected = ['!!unicorn.js', '!unicorn.js']; | ||
t.deepEqual(actual, expected); | ||
} | ||
}); |
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 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 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 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
Oops, something went wrong.