From d3214e90023a860318d3a3acbe14dcc5f84f549d Mon Sep 17 00:00:00 2001 From: Paul Hawxby Date: Mon, 25 Jul 2022 18:39:43 +0100 Subject: [PATCH 1/3] feat: add multi-os testing --- .github/workflows/nodejs.yml | 19 +++++++++++++++++++ .github/workflows/{main.yml => test.yml} | 14 ++++++++++---- 2 files changed, 29 insertions(+), 4 deletions(-) create mode 100644 .github/workflows/nodejs.yml rename .github/workflows/{main.yml => test.yml} (63%) diff --git a/.github/workflows/nodejs.yml b/.github/workflows/nodejs.yml new file mode 100644 index 0000000..9e6b775 --- /dev/null +++ b/.github/workflows/nodejs.yml @@ -0,0 +1,19 @@ +name: Node CI + +on: + - push + - pull_request + +jobs: + test-ubuntu: + uses: ./.github/workflows/test.yml + with: + os: ubuntu-latest + test-macos: + uses: ./.github/workflows/test.yml + with: + os: macos-latest + test-windows: + uses: ./.github/workflows/test.yml + with: + os: windows-latest diff --git a/.github/workflows/main.yml b/.github/workflows/test.yml similarity index 63% rename from .github/workflows/main.yml rename to .github/workflows/test.yml index 3b8aa86..b08211e 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/test.yml @@ -1,15 +1,21 @@ name: CI + on: - - push - - pull_request + workflow_call: + inputs: + os: + required: true + type: string + jobs: test: - name: Node.js ${{ matrix.node-version }} - runs-on: ubuntu-latest + name: Node.js ${{ matrix.node-version }} on ${{ inputs.os }} + runs-on: ${{ inputs.os }} strategy: fail-fast: false matrix: node-version: + - 18 - 16 - 14 - 12 From 572201674d7fca71ba5c1152ab46f6c15dc34aa1 Mon Sep 17 00:00:00 2001 From: Paul Hawxby Date: Mon, 25 Jul 2022 18:42:53 +0100 Subject: [PATCH 2/3] fix: github actions on windows throwing an error --- index.js | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/index.js b/index.js index 55f813c..8a2a16d 100644 --- a/index.js +++ b/index.js @@ -91,14 +91,19 @@ function _supportsColor(haveStream, {streamIsTTY, sniffFlags = true} = {}) { } if (process.platform === 'win32') { - // Windows 10 build 10586 is the first Windows release that supports 256 colors. - // Windows 10 build 14931 is the first release that supports 16m/TrueColor. - const osRelease = os.release().split('.'); - if ( - Number(osRelease[0]) >= 10 - && Number(osRelease[2]) >= 10_586 - ) { - return Number(osRelease[2]) >= 14_931 ? 3 : 2; + // Optional chaining support didn't drop until Node 14 so using the long-form. + const osRelease = os.release(); + + if (osRelease) { + // Windows 10 build 10586 is the first Windows release that supports 256 colors. + // Windows 10 build 14931 is the first release that supports 16m/TrueColor. + const splitOsRelease = osRelease.split('.'); + if ( + Number(splitOsRelease[0]) >= 10 + && Number(splitOsRelease[2]) >= 10_586 + ) { + return Number(splitOsRelease[2]) >= 14_931 ? 3 : 2; + } } return 1; From 7bc9db8688fcce6bc9914c8ccff334ea856c1aee Mon Sep 17 00:00:00 2001 From: Paul Hawxby Date: Mon, 25 Jul 2022 18:50:20 +0100 Subject: [PATCH 3/3] test: add os release undefined test --- index.js | 36 ++++++++++++++++++++---------------- test.js | 12 ++++++++++++ 2 files changed, 32 insertions(+), 16 deletions(-) diff --git a/index.js b/index.js index 8a2a16d..d002931 100644 --- a/index.js +++ b/index.js @@ -56,6 +56,25 @@ function translateLevel(level) { }; } +function getWin32Support() { + // Optional chaining support didn't drop until Node 14 so using the long-form. + const osRelease = os.release(); + + if (osRelease) { + // Windows 10 build 10586 is the first Windows release that supports 256 colors. + // Windows 10 build 14931 is the first release that supports 16m/TrueColor. + const splitOsRelease = osRelease.split('.'); + if ( + Number(splitOsRelease[0]) >= 10 + && Number(splitOsRelease[2]) >= 10_586 + ) { + return Number(splitOsRelease[2]) >= 14_931 ? 3 : 2; + } + } + + return 1; +} + function _supportsColor(haveStream, {streamIsTTY, sniffFlags = true} = {}) { const noFlagForceColor = envForceColor(); if (noFlagForceColor !== undefined) { @@ -91,22 +110,7 @@ function _supportsColor(haveStream, {streamIsTTY, sniffFlags = true} = {}) { } if (process.platform === 'win32') { - // Optional chaining support didn't drop until Node 14 so using the long-form. - const osRelease = os.release(); - - if (osRelease) { - // Windows 10 build 10586 is the first Windows release that supports 256 colors. - // Windows 10 build 14931 is the first release that supports 16m/TrueColor. - const splitOsRelease = osRelease.split('.'); - if ( - Number(splitOsRelease[0]) >= 10 - && Number(splitOsRelease[2]) >= 10_586 - ) { - return Number(splitOsRelease[2]) >= 14_931 ? 3 : 2; - } - } - - return 1; + return getWin32Support(); } if ('CI' in env) { diff --git a/test.js b/test.js index 8866073..4729a21 100644 --- a/test.js +++ b/test.js @@ -317,6 +317,18 @@ test('return level 3 if on Windows 10 build 14931 or later', t => { t.is(result.stdout.level, 3); }); +test('return level 1 if os release is undefined', t => { + Object.defineProperty(process, 'platform', { + value: 'win32', + }); + Object.defineProperty(process.versions, 'node', { + value: '8.0.0', + }); + os.release = () => undefined; + const result = importFresh('./index.js'); + t.is(result.stdout.level, 1); +}); + test('return level 2 when FORCE_COLOR is set when not TTY in xterm256', t => { process.stdout.isTTY = false; process.env.FORCE_COLOR = true;