Refactor unit tests to use mocks

This commit is contained in:
Sergei Zharinov 2022-02-21 23:49:37 +03:00
parent f71ef226d2
commit 418cc74752
7 changed files with 365 additions and 243 deletions

View File

@ -1,85 +1,140 @@
import io = require('@actions/io')
import os = require('os')
import fs = require('fs')
import path = require('path')
import * as _core from '@actions/core'
import * as _exec from '@actions/exec'
import * as _io from '@actions/io'
import * as _ioUtil from '@actions/io/lib/io-util'
import * as _tc from '@actions/tool-cache'
import * as _os from 'os'
import {join} from 'path'
const toolDir = path.join(__dirname, 'runner', 'tools', 'boot')
const tempDir = path.join(__dirname, 'runner', 'temp', 'boot')
process.env['RUNNER_TOOL_CACHE'] = toolDir
process.env['RUNNER_TEMP'] = tempDir
import * as boot from '../src/boot'
import {getCacheVersionString} from '../src/utils'
const toolPath = join(__dirname, 'runner', 'tools', 'boot')
const tempPath = join(__dirname, 'runner', 'temp', 'boot')
const downloadPath = join(__dirname, 'runner', 'download')
const cachePath = join(__dirname, 'runner', 'cache')
jest.mock('@actions/core')
const core: jest.Mocked<typeof _core> = _core as never
jest.mock('@actions/exec')
const exec: jest.Mocked<typeof _exec> = _exec as never
jest.mock('@actions/io')
const io: jest.Mocked<typeof _io> = _io as never
jest.mock('@actions/io/lib/io-util')
const ioUtil: jest.Mocked<typeof _ioUtil> = _ioUtil as never
jest.mock('@actions/tool-cache')
const tc: jest.Mocked<typeof _tc> = _tc as never
jest.mock('os')
const os: jest.Mocked<typeof _os> = _os as never
describe('boot tests', () => {
beforeAll(async () => {
await io.rmRF(toolDir)
await io.rmRF(tempDir)
}, 300000)
process.env['RUNNER_TOOL_CACHE'] = toolPath
process.env['RUNNER_TEMP'] = tempPath
os.arch.mockReturnValue('x64')
os.platform.mockReturnValue('linux')
jest.spyOn(global.Math, 'random').mockReturnValue(1)
})
afterAll(async () => {
try {
await io.rmRF(toolDir)
await io.rmRF(tempDir)
} catch {
console.log('Failed to remove test directories')
}
}, 100000)
jest.spyOn(global.Math, 'random').mockRestore()
jest.resetAllMocks()
delete process.env['RUNNER_TOOL_CACHE']
delete process.env['RUNNER_TEMP']
})
it('Throws if invalid version', async () => {
let thrown = false
try {
await boot.setup('1000')
} catch {
thrown = true
}
expect(thrown).toBe(true)
const msg = 'Unexpected HTTP response: 403'
tc.downloadTool.mockRejectedValueOnce(new Error(msg))
await expect(boot.setup('1000')).rejects.toThrow(msg)
})
it('Install boot with normal version', async () => {
await boot.setup('2.8.3')
const clojureDir = path.join(
toolDir,
'Boot',
getCacheVersionString('2.8.3'),
os.arch()
)
tc.downloadTool.mockResolvedValueOnce(downloadPath)
ioUtil.stat.mockResolvedValueOnce({isFile: () => true} as never)
tc.cacheDir.mockResolvedValueOnce(cachePath)
expect(fs.existsSync(`${clojureDir}.complete`)).toBe(true)
expect(fs.existsSync(path.join(clojureDir, 'bin', 'boot'))).toBe(true)
}, 100000)
await boot.setup('2.8.3')
expect(io.mkdirP).toHaveBeenNthCalledWith(
1,
join(tempPath, 'temp_2000000000')
)
expect(io.mkdirP).toHaveBeenNthCalledWith(
2,
join(tempPath, 'temp_2000000000', 'boot', 'bin')
)
expect(exec.exec.mock.calls[0]).toMatchObject([
'./boot -V',
[],
{
cwd: join(tempPath, 'temp_2000000000', 'boot', 'bin'),
env: {
BOOT_HOME: join(tempPath, 'temp_2000000000', 'boot'),
BOOT_VERSION: '2.8.3'
}
}
])
expect(tc.cacheDir).toHaveBeenCalledWith(
join(tempPath, 'temp_2000000000', 'boot'),
'Boot',
'2.8.3-3-6'
)
expect(core.exportVariable).toHaveBeenCalledWith(
'BOOT_HOME',
join(cachePath)
)
expect(core.addPath).toHaveBeenCalledWith(join(cachePath, 'bin'))
})
it('Install latest boot', async () => {
await boot.setup('latest')
const clojureDir = path.join(
toolDir,
'Boot',
getCacheVersionString('latest'),
os.arch()
)
tc.downloadTool.mockResolvedValueOnce(downloadPath)
ioUtil.stat.mockResolvedValueOnce({isFile: () => true} as never)
tc.cacheDir.mockResolvedValueOnce(cachePath)
expect(fs.existsSync(`${clojureDir}.complete`)).toBe(true)
expect(fs.existsSync(path.join(clojureDir, 'bin', 'boot'))).toBe(true)
}, 100000)
await boot.setup('latest')
expect(io.mkdirP).toHaveBeenNthCalledWith(
1,
join(tempPath, 'temp_2000000000')
)
expect(io.mkdirP).toHaveBeenNthCalledWith(
2,
join(tempPath, 'temp_2000000000', 'boot', 'bin')
)
expect(exec.exec.mock.calls[0]).toMatchObject([
'./boot -u',
[],
{
cwd: join(tempPath, 'temp_2000000000', 'boot', 'bin'),
env: {
BOOT_HOME: join(tempPath, 'temp_2000000000', 'boot')
}
}
])
expect(tc.cacheDir).toHaveBeenCalledWith(
join(tempPath, 'temp_2000000000', 'boot'),
'Boot',
'latest.0.0-3-6'
)
expect(core.exportVariable).toHaveBeenCalledWith(
'BOOT_HOME',
join(cachePath)
)
expect(core.addPath).toHaveBeenCalledWith(join(cachePath, 'bin'))
})
it('Uses version of boot installed in cache', async () => {
const clojureDir: string = path.join(toolDir, 'Boot', '2.8.3', os.arch())
await io.mkdirP(clojureDir)
fs.writeFileSync(`${clojureDir}.complete`, 'hello')
tc.find.mockReturnValue(cachePath)
await boot.setup('2.8.3')
return
})
it('Doesnt use version of clojure that was only partially installed in cache', async () => {
const clojureDir: string = path.join(toolDir, 'Boot', '2.8.3', os.arch())
await io.mkdirP(clojureDir)
let thrown = false
try {
await boot.setup('1000')
} catch {
thrown = true
}
expect(thrown).toBe(true)
return
expect(core.exportVariable).toHaveBeenCalledWith(
'BOOT_HOME',
join(cachePath)
)
expect(core.addPath).toHaveBeenCalledWith(join(cachePath, 'bin'))
})
})

View File

@ -1,95 +1,139 @@
import io = require('@actions/io')
import os = require('os')
import fs = require('fs')
import path = require('path')
import * as _core from '@actions/core'
import * as _exec from '@actions/exec'
import * as _io from '@actions/io'
import * as _ioUtil from '@actions/io/lib/io-util'
import * as _tc from '@actions/tool-cache'
import * as _os from 'os'
import {join} from 'path'
const toolDir = path.join(__dirname, 'runner', 'tools', 'leiningen')
const tempDir = path.join(__dirname, 'runner', 'temp', 'leiningen')
const toolPath = join(__dirname, 'runner', 'tools', 'leiningen')
const tempPath = join(__dirname, 'runner', 'temp', 'leiningen')
const downloadPath = join(__dirname, 'runner', 'download')
const cachePath = join(__dirname, 'runner', 'cache')
process.env['RUNNER_TOOL_CACHE'] = toolDir
process.env['RUNNER_TEMP'] = tempDir
import * as leiningen from '../src/leiningen'
import {getCacheVersionString} from '../src/utils'
jest.mock('@actions/core')
const core: jest.Mocked<typeof _core> = _core as never
jest.mock('@actions/exec')
const exec: jest.Mocked<typeof _exec> = _exec as never
jest.mock('@actions/io')
const io: jest.Mocked<typeof _io> = _io as never
jest.mock('@actions/io/lib/io-util')
const ioUtil: jest.Mocked<typeof _ioUtil> = _ioUtil as never
jest.mock('@actions/tool-cache')
const tc: jest.Mocked<typeof _tc> = _tc as never
jest.mock('os')
const os: jest.Mocked<typeof _os> = _os as never
describe('leiningen tests', () => {
beforeAll(async () => {
await io.rmRF(toolDir)
await io.rmRF(tempDir)
}, 300000)
beforeEach(async () => {
process.env['RUNNER_TOOL_CACHE'] = toolPath
process.env['RUNNER_TEMP'] = tempPath
os.arch.mockReturnValue('x64')
os.platform.mockReturnValue('linux')
jest.spyOn(global.Math, 'random').mockReturnValue(1)
})
afterAll(async () => {
try {
await io.rmRF(toolDir)
await io.rmRF(tempDir)
} catch {
console.log('Failed to remove test directories')
}
}, 100000)
afterEach(async () => {
jest.spyOn(global.Math, 'random').mockRestore()
jest.resetAllMocks()
delete process.env['RUNNER_TOOL_CACHE']
delete process.env['RUNNER_TEMP']
})
it('Throws if invalid version', async () => {
let thrown = false
try {
await leiningen.setup('1000')
} catch {
thrown = true
}
expect(thrown).toBe(true)
const msg = 'Unexpected HTTP response: 403'
tc.downloadTool.mockRejectedValueOnce(new Error(msg))
await expect(leiningen.setup('1000')).rejects.toThrow(msg)
})
it('Install leiningen with normal version', async () => {
await leiningen.setup('2.9.1')
const clojureDir = path.join(
toolDir,
'Leiningen',
getCacheVersionString('2.9.1'),
os.arch()
)
tc.downloadTool.mockResolvedValueOnce(downloadPath)
ioUtil.stat.mockResolvedValueOnce({isFile: () => true} as never)
tc.cacheDir.mockResolvedValueOnce(cachePath)
expect(fs.existsSync(`${clojureDir}.complete`)).toBe(true)
expect(fs.existsSync(path.join(clojureDir, 'bin', 'lein'))).toBe(true)
}, 100000)
await leiningen.setup('2.9.1')
expect(io.mkdirP).toHaveBeenNthCalledWith(
1,
join(tempPath, 'temp_2000000000')
)
expect(io.mkdirP).toHaveBeenNthCalledWith(
2,
join(tempPath, 'temp_2000000000', 'leiningen', 'bin')
)
expect(exec.exec.mock.calls[0]).toMatchObject([
'./lein version',
[],
{
cwd: join(tempPath, 'temp_2000000000', 'leiningen', 'bin'),
env: {
LEIN_HOME: join(tempPath, 'temp_2000000000', 'leiningen')
}
}
])
expect(tc.cacheDir).toHaveBeenCalledWith(
join(tempPath, 'temp_2000000000', 'leiningen'),
'Leiningen',
'2.9.1-3-6'
)
expect(core.exportVariable).toHaveBeenCalledWith(
'LEIN_HOME',
join(cachePath)
)
expect(core.addPath).toHaveBeenCalledWith(join(cachePath, 'bin'))
})
it('Install latest leiningen', async () => {
await leiningen.setup('latest')
const clojureDir = path.join(
toolDir,
'Leiningen',
getCacheVersionString('latest'),
os.arch()
)
tc.downloadTool.mockResolvedValueOnce(downloadPath)
ioUtil.stat.mockResolvedValueOnce({isFile: () => true} as never)
tc.cacheDir.mockResolvedValueOnce(cachePath)
expect(fs.existsSync(`${clojureDir}.complete`)).toBe(true)
expect(fs.existsSync(path.join(clojureDir, 'bin', 'lein'))).toBe(true)
}, 100000)
await leiningen.setup('latest')
expect(io.mkdirP).toHaveBeenNthCalledWith(
1,
join(tempPath, 'temp_2000000000')
)
expect(io.mkdirP).toHaveBeenNthCalledWith(
2,
join(tempPath, 'temp_2000000000', 'leiningen', 'bin')
)
expect(exec.exec.mock.calls[0]).toMatchObject([
'./lein version',
[],
{
cwd: join(tempPath, 'temp_2000000000', 'leiningen', 'bin'),
env: {
LEIN_HOME: join(tempPath, 'temp_2000000000', 'leiningen')
}
}
])
expect(tc.cacheDir).toHaveBeenCalledWith(
join(tempPath, 'temp_2000000000', 'leiningen'),
'Leiningen',
'latest.0.0-3-6'
)
expect(core.exportVariable).toHaveBeenCalledWith(
'LEIN_HOME',
join(cachePath)
)
expect(core.addPath).toHaveBeenCalledWith(join(cachePath, 'bin'))
})
it('Uses version of leiningen installed in cache', async () => {
const clojureDir: string = path.join(
toolDir,
'Leiningen',
'2.9.1',
os.arch()
)
await io.mkdirP(clojureDir)
fs.writeFileSync(`${clojureDir}.complete`, 'hello')
tc.find.mockReturnValue(cachePath)
await leiningen.setup('2.9.1')
return
})
it('Doesnt use version of clojure that was only partially installed in cache', async () => {
const clojureDir: string = path.join(
toolDir,
'Leiningen',
'2.9.1',
os.arch()
expect(core.exportVariable).toHaveBeenCalledWith(
'LEIN_HOME',
join(cachePath)
)
await io.mkdirP(clojureDir)
let thrown = false
try {
await leiningen.setup('1000')
} catch {
thrown = true
}
expect(thrown).toBe(true)
return
expect(core.addPath).toHaveBeenCalledWith(join(cachePath, 'bin'))
})
})

View File

@ -1,96 +1,117 @@
import io = require('@actions/io')
import exec = require('@actions/exec')
import os = require('os')
import fs = require('fs')
import path = require('path')
import * as _core from '@actions/core'
import * as _exec from '@actions/exec'
import * as _io from '@actions/io'
import * as _tc from '@actions/tool-cache'
import * as _os from 'os'
import {join} from 'path'
const toolDir = path.join(__dirname, 'runner', 'tools', 'tdeps')
const tempDir = path.join(__dirname, 'runner', 'temp', 'tdeps')
process.env['RUNNER_TOOL_CACHE'] = toolDir
process.env['RUNNER_TEMP'] = tempDir
import * as tdeps from '../src/cli'
import {getCacheVersionString} from '../src/utils'
const toolPath = join(__dirname, 'runner', 'tools', 'tdeps')
const tempPath = join(__dirname, 'runner', 'temp', 'tdeps')
const downloadPath = join(__dirname, 'runner', 'download')
const cachePath = join(__dirname, 'runner', 'cache')
jest.mock('@actions/core')
const core: jest.Mocked<typeof _core> = _core as never
jest.mock('@actions/exec')
const exec: jest.Mocked<typeof _exec> = _exec as never
jest.mock('@actions/io')
const io: jest.Mocked<typeof _io> = _io as never
jest.mock('@actions/tool-cache')
const tc: jest.Mocked<typeof _tc> = _tc as never
jest.mock('os')
const os: jest.Mocked<typeof _os> = _os as never
describe('tdeps tests', () => {
beforeAll(async () => {
await io.rmRF(toolDir)
await io.rmRF(tempDir)
}, 300000)
process.env['RUNNER_TOOL_CACHE'] = toolPath
process.env['RUNNER_TEMP'] = tempPath
os.arch.mockReturnValue('x64')
os.platform.mockReturnValue('linux')
jest.spyOn(global.Math, 'random').mockReturnValue(1)
})
afterAll(async () => {
try {
await io.rmRF(toolDir)
await io.rmRF(tempDir)
} catch {
console.log('Failed to remove test directories')
}
}, 100000)
jest.spyOn(global.Math, 'random').mockRestore()
jest.resetAllMocks()
delete process.env['RUNNER_TOOL_CACHE']
delete process.env['RUNNER_TEMP']
})
it('Throws if invalid version', async () => {
let thrown = false
try {
await tdeps.setup('1000')
} catch {
thrown = true
}
expect(thrown).toBe(true)
const msg = 'Unexpected HTTP response: 403'
tc.downloadTool.mockRejectedValueOnce(new Error(msg))
await expect(tdeps.setup('1000')).rejects.toThrow(msg)
})
it('Install clojure tools deps with normal version', async () => {
await tdeps.setup('1.10.1.469')
const clojureDir = path.join(
toolDir,
'ClojureToolsDeps',
getCacheVersionString('1.10.1.469'),
os.arch()
)
tc.downloadTool.mockResolvedValueOnce(downloadPath)
tc.cacheDir.mockResolvedValueOnce(cachePath)
expect(fs.existsSync(`${clojureDir}.complete`)).toBe(true)
expect(fs.existsSync(path.join(clojureDir, 'bin', 'clojure'))).toBe(true)
}, 100000)
await tdeps.setup('1.10.1.469')
expect(tc.downloadTool).toHaveBeenCalledWith(
'https://download.clojure.org/install/linux-install-1.10.1.469.sh'
)
expect(io.mkdirP).toHaveBeenCalledWith(join(tempPath, 'temp_2000000000'))
expect(exec.exec).toHaveBeenCalledWith('bash', [
downloadPath,
'--prefix',
join(tempPath, 'temp_2000000000')
])
expect(tc.cacheDir).toHaveBeenCalledWith(
join(tempPath, 'temp_2000000000'),
'ClojureToolsDeps',
'1.10.1-469-3-6'
)
expect(core.exportVariable).toHaveBeenCalledWith(
'CLOJURE_INSTALL_DIR',
join(cachePath, 'lib', 'clojure')
)
expect(core.addPath).toHaveBeenCalledWith(join(cachePath, 'bin'))
})
it('Install latest clojure tools deps', async () => {
await tdeps.setup('latest')
const clojureDir = path.join(
toolDir,
'ClojureToolsDeps',
getCacheVersionString('latest'),
os.arch()
)
tc.downloadTool.mockResolvedValueOnce(downloadPath)
tc.cacheDir.mockResolvedValueOnce(cachePath)
expect(fs.existsSync(`${clojureDir}.complete`)).toBe(true)
expect(fs.existsSync(path.join(clojureDir, 'bin', 'clojure'))).toBe(true)
}, 100000)
await tdeps.setup('latest')
expect(tc.downloadTool).toHaveBeenCalledWith(
'https://download.clojure.org/install/linux-install.sh'
)
expect(io.mkdirP).toHaveBeenCalledWith(join(tempPath, 'temp_2000000000'))
expect(exec.exec).toHaveBeenCalledWith('bash', [
downloadPath,
'--prefix',
join(tempPath, 'temp_2000000000')
])
expect(tc.cacheDir).toHaveBeenCalledWith(
join(tempPath, 'temp_2000000000'),
'ClojureToolsDeps',
'latest.0.0-3-6'
)
expect(core.exportVariable).toHaveBeenCalledWith(
'CLOJURE_INSTALL_DIR',
join(cachePath, 'lib', 'clojure')
)
expect(core.addPath).toHaveBeenCalledWith(join(cachePath, 'bin'))
})
it('Uses version of clojure tools-deps installed in cache', async () => {
const clojureDir: string = path.join(
toolDir,
'ClojureToolsDeps',
getCacheVersionString('1.10.1.469'),
os.arch()
)
await io.mkdirP(clojureDir)
fs.writeFileSync(`${clojureDir}.complete`, 'hello')
await tdeps.setup('1.10.1.469')
return
})
tc.find.mockReturnValue(cachePath)
it('Doesnt use version of clojure that was only partially installed in cache', async () => {
const clojureDir: string = path.join(
toolDir,
'ClojureToolsDeps',
'1.10.1-469',
os.arch()
await tdeps.setup('1.10.1.469')
expect(core.exportVariable).toHaveBeenCalledWith(
'CLOJURE_INSTALL_DIR',
join(cachePath, 'lib', 'clojure')
)
await io.mkdirP(clojureDir)
let thrown = false
try {
await tdeps.setup('1000')
} catch {
thrown = true
}
expect(thrown).toBe(true)
return
expect(core.addPath).toHaveBeenCalledWith(join(cachePath, 'bin'))
})
})

View File

@ -1,27 +1,29 @@
import * as core from '@actions/core'
import * as io from '@actions/io'
import * as ioUtil from '@actions/io/lib/io-util'
import * as tc from '@actions/tool-cache'
import * as exec from '@actions/exec'
import * as fs from 'fs'
import * as path from 'path'
import * as os from 'os'
import * as utils from './utils'
let tempDirectory = process.env['RUNNER_TEMP'] || ''
const IS_WINDOWS = process.platform === 'win32'
function getTempDirectory(): string {
let tempDirectory = process.env['RUNNER_TEMP'] || ''
if (!tempDirectory) {
let baseLocation
if (IS_WINDOWS) {
baseLocation = process.env['USERPROFILE'] || 'C:\\'
} else {
if (process.platform === 'darwin') {
baseLocation = '/Users'
if (!tempDirectory) {
let baseLocation
if (utils.isWindows()) {
baseLocation = process.env['USERPROFILE'] || 'C:\\'
} else {
baseLocation = '/home'
if (process.platform === 'darwin') {
baseLocation = '/Users'
} else {
baseLocation = '/home'
}
}
tempDirectory = path.join(baseLocation, 'actions', 'temp')
}
tempDirectory = path.join(baseLocation, 'actions', 'temp')
return tempDirectory
}
export async function setup(
@ -43,7 +45,7 @@ export async function setup(
githubAuth
)
const tempDir: string = path.join(
tempDirectory,
getTempDirectory(),
`temp_${Math.floor(Math.random() * 2000000000)}`
)
const bootDir = await installBoot(bootBootstrapFile, tempDir, version)
@ -70,14 +72,14 @@ async function installBoot(
await io.mkdirP(destinationFolder)
const bin = path.normalize(binScript)
const binStats = fs.statSync(bin)
const binStats = await ioUtil.stat(bin)
if (binStats.isFile()) {
const binDir = path.join(destinationFolder, 'boot', 'bin')
await io.mkdirP(binDir)
await io.mv(bin, path.join(binDir, `boot`))
fs.chmodSync(path.join(binDir, `boot`), '0755')
await ioUtil.chmod(path.join(binDir, `boot`), '0755')
let env: {[key: string]: string} = {}
if (version === 'latest') {

View File

@ -7,8 +7,6 @@ import * as path from 'path'
import * as os from 'os'
import * as utils from './utils'
const tempDirectory = utils.getTempDir()
export async function setup(
version: string,
githubToken?: string
@ -23,7 +21,7 @@ export async function setup(
core.info(`Clojure CLI found in cache ${toolPath}`)
} else {
const tempDir: string = path.join(
tempDirectory,
utils.getTempDir(),
`temp_${Math.floor(Math.random() * 2000000000)}`
)
const clojureInstallScript = await tc.downloadTool(

View File

@ -2,18 +2,17 @@ import * as core from '@actions/core'
import * as io from '@actions/io'
import * as tc from '@actions/tool-cache'
import * as exec from '@actions/exec'
import * as fs from 'fs'
import * as ioUtil from '@actions/io/lib/io-util'
import * as path from 'path'
import * as os from 'os'
import * as utils from './utils'
const tempDirectory = utils.getTempDir()
const IS_WINDOWS = utils.isWindows()
export async function setup(
version: string,
githubAuth?: string
): Promise<void> {
const isWindows = utils.isWindows()
let toolPath = tc.find(
'Leiningen',
utils.getCacheVersionString(version),
@ -26,12 +25,12 @@ export async function setup(
const leiningenFile = await tc.downloadTool(
`https://raw.githubusercontent.com/technomancy/leiningen/${
version === 'latest' ? 'stable' : version
}/bin/lein${IS_WINDOWS ? '.ps1' : ''}`,
}/bin/lein${isWindows ? '.ps1' : ''}`,
undefined,
githubAuth
)
const tempDir: string = path.join(
tempDirectory,
utils.getTempDir(),
`temp_${Math.floor(Math.random() * 2000000000)}`
)
const leiningenDir = await installLeiningen(leiningenFile, tempDir)
@ -51,22 +50,24 @@ async function installLeiningen(
binScript: string,
destinationFolder: string
): Promise<string> {
const isWindows = utils.isWindows()
await io.mkdirP(destinationFolder)
const bin = path.normalize(binScript)
const binStats = fs.statSync(bin)
const binStats = await ioUtil.stat(bin)
if (binStats.isFile()) {
const binDir = path.join(destinationFolder, 'leiningen', 'bin')
await io.mkdirP(binDir)
await io.mv(bin, path.join(binDir, `lein${IS_WINDOWS ? '.ps1' : ''}`))
await io.mv(bin, path.join(binDir, `lein${isWindows ? '.ps1' : ''}`))
if (!IS_WINDOWS) {
fs.chmodSync(path.join(binDir, `lein`), '0755')
if (!isWindows) {
await ioUtil.chmod(path.join(binDir, `lein`), '0755')
}
const version_cmd = IS_WINDOWS
const version_cmd = isWindows
? 'powershell .\\lein.ps1 self-install'
: './lein version'

View File

@ -1,3 +1,4 @@
import os from 'os'
import * as path from 'path'
import {VERSION} from './version'
@ -31,9 +32,9 @@ export function getTempDir(): string {
}
export function isWindows(): boolean {
return process.platform === 'win32'
return os.platform() === 'win32'
}
export function isMacOS(): boolean {
return process.platform === 'darwin'
return os.platform() === 'darwin'
}