@@ -5,10 +5,10 @@ import slash from 'slash';
5
5
import { isGitIgnored , isGitIgnoredSync } from './gitignore.js' ;
6
6
7
7
const __dirname = path . dirname ( fileURLToPath ( import . meta. url ) ) ;
8
- const getCwdValues = cwd => [ cwd , pathToFileURL ( cwd ) , pathToFileURL ( cwd ) . href ] ;
8
+ const getPathValues = cwd => [ cwd , pathToFileURL ( cwd ) , pathToFileURL ( cwd ) . href ] ;
9
9
10
10
test ( 'gitignore' , async t => {
11
- for ( const cwd of getCwdValues ( path . join ( __dirname , 'fixtures/gitignore' ) ) ) {
11
+ for ( const cwd of getPathValues ( path . join ( __dirname , 'fixtures/gitignore' ) ) ) {
12
12
// eslint-disable-next-line no-await-in-loop
13
13
const isIgnored = await isGitIgnored ( { cwd} ) ;
14
14
const actual = [ 'foo.js' , 'bar.js' ] . filter ( file => ! isIgnored ( file ) ) ;
@@ -19,7 +19,7 @@ test('gitignore', async t => {
19
19
20
20
test ( 'gitignore - mixed path styles' , async t => {
21
21
const directory = path . join ( __dirname , 'fixtures/gitignore' ) ;
22
- for ( const cwd of getCwdValues ( directory ) ) {
22
+ for ( const cwd of getPathValues ( directory ) ) {
23
23
// eslint-disable-next-line no-await-in-loop
24
24
const isIgnored = await isGitIgnored ( { cwd} ) ;
25
25
t . true ( isIgnored ( slash ( path . resolve ( directory , 'foo.js' ) ) ) ) ;
@@ -28,15 +28,15 @@ test('gitignore - mixed path styles', async t => {
28
28
29
29
test ( 'gitignore - os paths' , async t => {
30
30
const directory = path . join ( __dirname , 'fixtures/gitignore' ) ;
31
- for ( const cwd of getCwdValues ( directory ) ) {
31
+ for ( const cwd of getPathValues ( directory ) ) {
32
32
// eslint-disable-next-line no-await-in-loop
33
33
const isIgnored = await isGitIgnored ( { cwd} ) ;
34
34
t . true ( isIgnored ( path . resolve ( directory , 'foo.js' ) ) ) ;
35
35
}
36
36
} ) ;
37
37
38
38
test ( 'gitignore - sync' , t => {
39
- for ( const cwd of getCwdValues ( path . join ( __dirname , 'fixtures/gitignore' ) ) ) {
39
+ for ( const cwd of getPathValues ( path . join ( __dirname , 'fixtures/gitignore' ) ) ) {
40
40
const isIgnored = isGitIgnoredSync ( { cwd} ) ;
41
41
const actual = [ 'foo.js' , 'bar.js' ] . filter ( file => ! isIgnored ( file ) ) ;
42
42
const expected = [ 'bar.js' ] ;
@@ -47,7 +47,7 @@ test('gitignore - sync', t => {
47
47
test ( 'ignore ignored .gitignore' , async t => {
48
48
const ignore = [ '**/.gitignore' ] ;
49
49
50
- for ( const cwd of getCwdValues ( path . join ( __dirname , 'fixtures/gitignore' ) ) ) {
50
+ for ( const cwd of getPathValues ( path . join ( __dirname , 'fixtures/gitignore' ) ) ) {
51
51
// eslint-disable-next-line no-await-in-loop
52
52
const isIgnored = await isGitIgnored ( { cwd, ignore} ) ;
53
53
const actual = [ 'foo.js' , 'bar.js' ] . filter ( file => ! isIgnored ( file ) ) ;
@@ -59,7 +59,7 @@ test('ignore ignored .gitignore', async t => {
59
59
test ( 'ignore ignored .gitignore - sync' , t => {
60
60
const ignore = [ '**/.gitignore' ] ;
61
61
62
- for ( const cwd of getCwdValues ( path . join ( __dirname , 'fixtures/gitignore' ) ) ) {
62
+ for ( const cwd of getPathValues ( path . join ( __dirname , 'fixtures/gitignore' ) ) ) {
63
63
const isIgnored = isGitIgnoredSync ( { cwd, ignore} ) ;
64
64
const actual = [ 'foo.js' , 'bar.js' ] . filter ( file => ! isIgnored ( file ) ) ;
65
65
const expected = [ 'foo.js' , 'bar.js' ] ;
@@ -68,7 +68,7 @@ test('ignore ignored .gitignore - sync', t => {
68
68
} ) ;
69
69
70
70
test ( 'negative gitignore' , async t => {
71
- for ( const cwd of getCwdValues ( path . join ( __dirname , 'fixtures/negative' ) ) ) {
71
+ for ( const cwd of getPathValues ( path . join ( __dirname , 'fixtures/negative' ) ) ) {
72
72
// eslint-disable-next-line no-await-in-loop
73
73
const isIgnored = await isGitIgnored ( { cwd} ) ;
74
74
const actual = [ 'foo.js' , 'bar.js' ] . filter ( file => ! isIgnored ( file ) ) ;
@@ -78,7 +78,7 @@ test('negative gitignore', async t => {
78
78
} ) ;
79
79
80
80
test ( 'negative gitignore - sync' , t => {
81
- for ( const cwd of getCwdValues ( path . join ( __dirname , 'fixtures/negative' ) ) ) {
81
+ for ( const cwd of getPathValues ( path . join ( __dirname , 'fixtures/negative' ) ) ) {
82
82
const isIgnored = isGitIgnoredSync ( { cwd} ) ;
83
83
const actual = [ 'foo.js' , 'bar.js' ] . filter ( file => ! isIgnored ( file ) ) ;
84
84
const expected = [ 'foo.js' ] ;
@@ -87,7 +87,7 @@ test('negative gitignore - sync', t => {
87
87
} ) ;
88
88
89
89
test ( 'multiple negation' , async t => {
90
- for ( const cwd of getCwdValues ( path . join ( __dirname , 'fixtures/multiple-negation' ) ) ) {
90
+ for ( const cwd of getPathValues ( path . join ( __dirname , 'fixtures/multiple-negation' ) ) ) {
91
91
// eslint-disable-next-line no-await-in-loop
92
92
const isIgnored = await isGitIgnored ( { cwd} ) ;
93
93
@@ -104,7 +104,7 @@ test('multiple negation', async t => {
104
104
} ) ;
105
105
106
106
test ( 'multiple negation - sync' , t => {
107
- for ( const cwd of getCwdValues ( path . join ( __dirname , 'fixtures/multiple-negation' ) ) ) {
107
+ for ( const cwd of getPathValues ( path . join ( __dirname , 'fixtures/multiple-negation' ) ) ) {
108
108
const isIgnored = isGitIgnoredSync ( { cwd} ) ;
109
109
110
110
const actual = [
@@ -118,3 +118,21 @@ test('multiple negation - sync', t => {
118
118
t . deepEqual ( actual , expected ) ;
119
119
}
120
120
} ) ;
121
+
122
+ test ( 'check file' , async t => {
123
+ const directory = path . join ( __dirname , 'fixtures/gitignore' ) ;
124
+ const ignoredFile = path . join ( directory , 'foo.js' ) ;
125
+ const isIgnored = await isGitIgnored ( { cwd : directory } ) ;
126
+ const isIgnoredSync = isGitIgnoredSync ( { cwd : directory } ) ;
127
+
128
+ for ( const file of getPathValues ( ignoredFile ) ) {
129
+ t . true ( isIgnored ( file ) ) ;
130
+ t . true ( isIgnored ( { path : file } ) ) ;
131
+ t . true ( isIgnoredSync ( file ) ) ;
132
+ t . true ( isIgnoredSync ( { path : file } ) ) ;
133
+ }
134
+
135
+ for ( const file of getPathValues ( path . join ( directory , 'bar.js' ) ) ) {
136
+ t . false ( isIgnored ( file ) ) ;
137
+ }
138
+ } ) ;
0 commit comments