1
1
import makeConsoleMock from 'consolemock'
2
2
import fs from 'fs-extra'
3
3
import ansiSerializer from 'jest-snapshot-serializer-ansi'
4
- import { nanoid } from 'nanoid'
5
4
import normalize from 'normalize-path'
6
- import os from 'os'
7
5
import path from 'path'
8
6
9
7
jest . unmock ( 'cosmiconfig' )
@@ -12,6 +10,7 @@ jest.unmock('execa')
12
10
import execGitBase from '../lib/execGit'
13
11
import lintStaged from '../lib/index'
14
12
import { replaceSerializer } from './utils/replaceSerializer'
13
+ import { createTempDir } from './utils/tempDir'
15
14
16
15
jest . setTimeout ( 20000 )
17
16
@@ -31,28 +30,6 @@ const testJsFileUnfixable = `const obj = {
31
30
32
31
const fixJsConfig = { config : { '*.js' : 'prettier --write' } }
33
32
34
- const isAppveyor = ! ! process . env . APPVEYOR
35
- const osTmpDir = isAppveyor ? 'C:\\projects' : fs . realpathSync ( os . tmpdir ( ) )
36
-
37
- /**
38
- * Create temporary directory and return its path
39
- * @returns {Promise<String> }
40
- */
41
- const createTempDir = async ( ) => {
42
- const dirname = path . resolve ( osTmpDir , 'lint-staged-test' , nanoid ( ) )
43
- await fs . ensureDir ( dirname )
44
- return dirname
45
- }
46
-
47
- /**
48
- * Remove temporary directory
49
- * @param {String } dirname
50
- * @returns {Promise<Void> }
51
- */
52
- const removeTempDir = async ( dirname ) => {
53
- await fs . remove ( dirname )
54
- }
55
-
56
33
let tmpDir
57
34
let cwd
58
35
@@ -90,7 +67,7 @@ describe('lint-staged', () => {
90
67
"
91
68
ERROR × Current directory is not a git directory!"
92
69
` )
93
- await removeTempDir ( nonGitDir )
70
+ await fs . remove ( nonGitDir )
94
71
} )
95
72
96
73
it ( 'should fail without output when not in a git directory and quiet' , async ( ) => {
@@ -100,12 +77,14 @@ describe('lint-staged', () => {
100
77
lintStaged ( { ...fixJsConfig , cwd : nonGitDir , quiet : true } , logger )
101
78
) . resolves . toEqual ( false )
102
79
expect ( logger . printHistory ( ) ) . toMatchInlineSnapshot ( `""` )
103
- await removeTempDir ( nonGitDir )
80
+ await fs . remove ( nonGitDir )
104
81
} )
105
82
} )
106
83
107
84
const globalConsoleTemp = console
108
85
86
+ const isAppveyor = ! ! process . env . APPVEYOR
87
+
109
88
describe ( 'lint-staged' , ( ) => {
110
89
beforeAll ( ( ) => {
111
90
console = makeConsoleMock ( )
@@ -126,7 +105,7 @@ describe('lint-staged', () => {
126
105
afterEach ( async ( ) => {
127
106
console . clearHistory ( )
128
107
if ( ! isAppveyor ) {
129
- await removeTempDir ( tmpDir )
108
+ await fs . remove ( tmpDir )
130
109
}
131
110
} )
132
111
0 commit comments