Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: remove nanoid devDependency to remove ExperimentalWarning #874

Merged
merged 1 commit into from May 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion package.json
Expand Up @@ -63,7 +63,6 @@
"husky": "^4.2.5",
"jest": "^26.0.1",
"jest-snapshot-serializer-ansi": "^1.0.0",
"nanoid": "^3.1.7",
"prettier": "^2.0.5"
},
"config": {
Expand Down
29 changes: 4 additions & 25 deletions test/gitWorkflow.spec.js
@@ -1,41 +1,18 @@
import fs from 'fs-extra'
import { nanoid } from 'nanoid'
import normalize from 'normalize-path'
import os from 'os'
import path from 'path'

import execGitBase from '../lib/execGit'
import { writeFile } from '../lib/file'
import GitWorkflow from '../lib/gitWorkflow'
import { getInitialState } from '../lib/state'
import { createTempDir } from './utils/tempDir'

jest.mock('../lib/file.js')
jest.unmock('execa')

jest.setTimeout(20000)

const isAppveyor = !!process.env.APPVEYOR
const osTmpDir = isAppveyor ? 'C:\\projects' : fs.realpathSync(os.tmpdir())

/**
* Create temporary directory and return its path
* @returns {Promise<String>}
*/
const createTempDir = async () => {
const dirname = path.resolve(osTmpDir, 'lint-staged-test', nanoid())
await fs.ensureDir(dirname)
return dirname
}

/**
* Remove temporary directory
* @param {String} dirname
* @returns {Promise<Void>}
*/
const removeTempDir = async (dirname) => {
await fs.remove(dirname)
}

let tmpDir, cwd

/** Append to file, creating if it doesn't exist */
Expand All @@ -55,6 +32,8 @@ const initGitRepo = async () => {
await execGit(['commit', '-m initial commit'])
}

const isAppveyor = !!process.env.APPVEYOR

describe('gitWorkflow', () => {
beforeEach(async () => {
tmpDir = await createTempDir()
Expand All @@ -64,7 +43,7 @@ describe('gitWorkflow', () => {

afterEach(async () => {
if (!isAppveyor) {
await removeTempDir(tmpDir)
await fs.remove(tmpDir)
}
})

Expand Down
33 changes: 6 additions & 27 deletions test/integration.test.js
@@ -1,9 +1,7 @@
import makeConsoleMock from 'consolemock'
import fs from 'fs-extra'
import ansiSerializer from 'jest-snapshot-serializer-ansi'
import { nanoid } from 'nanoid'
import normalize from 'normalize-path'
import os from 'os'
import path from 'path'

jest.unmock('cosmiconfig')
Expand All @@ -12,6 +10,7 @@ jest.unmock('execa')
import execGitBase from '../lib/execGit'
import lintStaged from '../lib/index'
import { replaceSerializer } from './utils/replaceSerializer'
import { createTempDir } from './utils/tempDir'

jest.setTimeout(20000)

Expand All @@ -31,28 +30,6 @@ const testJsFileUnfixable = `const obj = {

const fixJsConfig = { config: { '*.js': 'prettier --write' } }

const isAppveyor = !!process.env.APPVEYOR
const osTmpDir = isAppveyor ? 'C:\\projects' : fs.realpathSync(os.tmpdir())

/**
* Create temporary directory and return its path
* @returns {Promise<String>}
*/
const createTempDir = async () => {
const dirname = path.resolve(osTmpDir, 'lint-staged-test', nanoid())
await fs.ensureDir(dirname)
return dirname
}

/**
* Remove temporary directory
* @param {String} dirname
* @returns {Promise<Void>}
*/
const removeTempDir = async (dirname) => {
await fs.remove(dirname)
}

let tmpDir
let cwd

Expand Down Expand Up @@ -90,7 +67,7 @@ describe('lint-staged', () => {
"
ERROR × Current directory is not a git directory!"
`)
await removeTempDir(nonGitDir)
await fs.remove(nonGitDir)
})

it('should fail without output when not in a git directory and quiet', async () => {
Expand All @@ -100,12 +77,14 @@ describe('lint-staged', () => {
lintStaged({ ...fixJsConfig, cwd: nonGitDir, quiet: true }, logger)
).resolves.toEqual(false)
expect(logger.printHistory()).toMatchInlineSnapshot(`""`)
await removeTempDir(nonGitDir)
await fs.remove(nonGitDir)
})
})

const globalConsoleTemp = console

const isAppveyor = !!process.env.APPVEYOR

describe('lint-staged', () => {
beforeAll(() => {
console = makeConsoleMock()
Expand All @@ -126,7 +105,7 @@ describe('lint-staged', () => {
afterEach(async () => {
console.clearHistory()
if (!isAppveyor) {
await removeTempDir(tmpDir)
await fs.remove(tmpDir)
}
})

Expand Down
16 changes: 16 additions & 0 deletions test/utils/tempDir.js
@@ -0,0 +1,16 @@
import fs from 'fs-extra'
import os from 'os'
import path from 'path'

const osTmpDir = process.env.APPVEYOR ? 'C:\\projects' : fs.realpathSync(os.tmpdir())

/**
* Create temporary random directory and return its path
* @returns {Promise<String>}
*/
export const createTempDir = async () => {
const random = Date.now().toString(36) + Math.random().toString(36).substr(2)
const dirname = path.resolve(osTmpDir, `lint-staged-${random}`)
await fs.ensureDir(dirname)
return dirname
}
5 changes: 0 additions & 5 deletions yarn.lock
Expand Up @@ -4078,11 +4078,6 @@ mute-stream@0.0.8:
resolved "https://registry.yarnpkg.com/mute-stream/-/mute-stream-0.0.8.tgz#1630c42b2251ff81e2a283de96a5497ea92e5e0d"
integrity sha512-nnbWWOkoWyUsTjKrhgD0dcz22mdkSnpYqbEjIm2nhwhuxlSkpywJmBo8h0ZqJdkp73mb90SssHkN4rsRaBAfAA==

nanoid@^3.1.7:
version "3.1.7"
resolved "https://registry.yarnpkg.com/nanoid/-/nanoid-3.1.7.tgz#3705ccf590b6a51fbd1794fcf204ce7b5dc46c01"
integrity sha512-ruOwuatdEf4BxQmZopZqhIMudQ9V83aKocr+q2Y7KasnDNvo2OgbgZBYago5hSD0tCmoSl4flIw9ytDLIVM2IQ==

nanomatch@^1.2.9:
version "1.2.13"
resolved "https://registry.yarnpkg.com/nanomatch/-/nanomatch-1.2.13.tgz#b87a8aa4fc0de8fe6be88895b38983ff265bd119"
Expand Down