diff --git a/lib/index.js b/lib/index.js index 1d42204..571ff6b 100644 --- a/lib/index.js +++ b/lib/index.js @@ -131,7 +131,7 @@ const open = (_args, opts = {}, extra = {}) => { let platform = process.platform // process.platform === 'linux' may actually indicate WSL, if that's the case // we want to treat things as win32 anyway so the host can open the argument - if (platform === 'linux' && os.release().includes('Microsoft')) { + if (platform === 'linux' && os.release().toLowerCase().includes('microsoft')) { platform = 'win32' } diff --git a/test/open.js b/test/open.js index dfa16a8..674e721 100644 --- a/test/open.js +++ b/test/open.js @@ -180,6 +180,32 @@ t.test('process.platform === linux', (t) => { t.ok(proc.called) }) + t.test('when os.release() includes microsoft treats as win32', async (t) => { + const comSpec = process.env.ComSpec + process.env.ComSpec = 'C:\\Windows\\System32\\cmd.exe' + t.teardown(() => { + process.env.ComSPec = comSpec + }) + + const promiseSpawnMock = t.mock('../lib/index.js', { + os: { + release: () => 'microsoft', + }, + }) + + const proc = spawk.spawn('C:\\Windows\\System32\\cmd.exe', + ['/d', '/s', '/c', 'start "" https://google.com'], + { shell: false }) + + const result = await promiseSpawnMock.open('https://google.com') + t.hasStrict(result, { + code: 0, + signal: undefined, + }) + + t.ok(proc.called) + }) + t.end() })