Skip to content

Commit

Permalink
chore: skip umask tests in windows
Browse files Browse the repository at this point in the history
  • Loading branch information
wraithgar committed Jan 10, 2022
1 parent 69aa56d commit d26cd97
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions test/fix-bin.js
@@ -1,6 +1,7 @@
const t = require('tap')
const requireInject = require('require-inject')
const fixBin = require('../lib/fix-bin.js')
const isWindows = require('../lib/is-windows.js')
const umask = process.umask()
const fs = require('fs')
const { readFileSync, statSync, chmodSync } = fs
Expand All @@ -11,7 +12,9 @@ t.test('fix windows hashbang', t => {
})
chmodSync(`${dir}/whb`, 0o644)
return fixBin(`${dir}/whb`).then(() => {
t.equal((statSync(`${dir}/whb`).mode & 0o777), 0o777 & (~umask), 'has exec perms')
if (!isWindows) {
t.equal((statSync(`${dir}/whb`).mode & 0o777), 0o777 & (~umask), 'has exec perms')
}
t.equal(readFileSync(`${dir}/whb`, 'utf8'),
`#!/usr/bin/env node\nconsole.log('hello')\r\n`, 'fixed \\r on hashbang line')
})
Expand All @@ -23,7 +26,9 @@ t.test('dont fix non-windows hashbang file', t => {
})
chmodSync(`${dir}/goodhb`, 0o644)
return fixBin(`${dir}/goodhb`).then(() => {
t.equal((statSync(`${dir}/goodhb`).mode & 0o777), 0o777 & (~umask), 'has exec perms')
if (!isWindows) {
t.equal((statSync(`${dir}/goodhb`).mode & 0o777), 0o777 & (~umask), 'has exec perms')
}
t.equal(readFileSync(`${dir}/goodhb`, 'utf8'),
`#!/usr/bin/env node\nconsole.log('hello')\r\n`, 'fixed \\r on hashbang line')
})
Expand All @@ -46,7 +51,9 @@ t.test('failure to read means not a windows hash bang file', t => {
})
chmodSync(`${dir}/whb`, 0o644)
return fixBin(`${dir}/whb`).then(() => {
t.equal((statSync(`${dir}/whb`).mode & 0o777), 0o777 & (~umask), 'has exec perms')
if (!isWindows) {
t.equal((statSync(`${dir}/whb`).mode & 0o777), 0o777 & (~umask), 'has exec perms')
}
t.equal(readFileSync(`${dir}/whb`, 'utf8'),
/* eslint-disable-next-line max-len */
`#!/usr/bin/env node\r\nconsole.log('hello')\r\n`, 'did not fix \\r on hashbang line (failed read)')
Expand All @@ -70,7 +77,9 @@ t.test('failure to close is ignored', t => {
})
chmodSync(`${dir}/whb`, 0o644)
return fixBin(`${dir}/whb`).then(() => {
t.equal((statSync(`${dir}/whb`).mode & 0o777), 0o777 & (~umask), 'has exec perms')
if (!isWindows) {
t.equal((statSync(`${dir}/whb`).mode & 0o777), 0o777 & (~umask), 'has exec perms')
}
t.equal(readFileSync(`${dir}/whb`, 'utf8'),
/* eslint-disable-next-line max-len */
`#!/usr/bin/env node\nconsole.log('hello')\r\n`, 'fixed \\r on hashbang line (ignored failed close)')
Expand All @@ -83,7 +92,9 @@ t.test('custom exec mode', t => {
})
chmodSync(`${dir}/goodhb`, 0o644)
return fixBin(`${dir}/goodhb`, 0o755).then(() => {
t.equal((statSync(`${dir}/goodhb`).mode & 0o755), 0o755 & (~umask), 'has exec perms')
if (!isWindows) {
t.equal((statSync(`${dir}/goodhb`).mode & 0o755), 0o755 & (~umask), 'has exec perms')
}
t.equal(readFileSync(`${dir}/goodhb`, 'utf8'),
`#!/usr/bin/env node\nconsole.log('hello')\r\n`, 'fixed \\r on hashbang line')
})
Expand All @@ -95,7 +106,9 @@ t.test('custom exec mode in windows', t => {
})
chmodSync(`${dir}/goodhb`, 0o644)
return fixBin(`${dir}/goodhb`, 0o755).then(() => {
t.equal((statSync(`${dir}/goodhb`).mode & 0o755), 0o755 & (~umask), 'has exec perms')
if (!isWindows) {
t.equal((statSync(`${dir}/goodhb`).mode & 0o755), 0o755 & (~umask), 'has exec perms')
}
t.equal(readFileSync(`${dir}/goodhb`, 'utf8'),
`#!/usr/bin/env node\nconsole.log('hello')\r\n`, 'fixed \\r on hashbang line')
})
Expand Down

0 comments on commit d26cd97

Please sign in to comment.