Skip to content

Commit

Permalink
fix: remove nanoid devDependency to remove ExperimentalWarning (#874)
Browse files Browse the repository at this point in the history
nanoid contains conditional exports and emits a warning on Node.js >= 13.7: `ExperimentalWarning: Conditional exports is an experimental feature. This feature could change at any time`
  • Loading branch information
iiroj committed May 22, 2020
1 parent b8e1a4a commit 979da5d
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 58 deletions.
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

0 comments on commit 979da5d

Please sign in to comment.