From 3b0cedef4747551d3e63108f6953fd64046c8bf7 Mon Sep 17 00:00:00 2001 From: Gant Laborde Date: Mon, 26 Feb 2018 22:19:26 -0600 Subject: [PATCH] :rage3: windows working and fight node modules (#179) * windows working * improve style and verbiage --- .vscode/cSpell.json | 2 ++ __tests__/__mocks__/mockContext.ts | 4 +++ __tests__/command_helpers/checkCLI.ts | 9 ++++++ __tests__/command_helpers/getVersion.ts | 2 +- .../command_helpers/quirksNodeModules.ts | 32 +++++++++++++++++++ src/extensions/functions/checkCLI.ts | 2 ++ .../functions/checkCLIForUpdates.ts | 3 +- src/extensions/functions/quirksNodeModules.ts | 9 ++++++ src/extensions/functions/updateRequirement.ts | 3 +- 9 files changed, 63 insertions(+), 3 deletions(-) create mode 100644 __tests__/command_helpers/quirksNodeModules.ts create mode 100644 src/extensions/functions/quirksNodeModules.ts diff --git a/.vscode/cSpell.json b/.vscode/cSpell.json index dab156f..025b4e9 100644 --- a/.vscode/cSpell.json +++ b/.vscode/cSpell.json @@ -18,6 +18,7 @@ "config", "configs", "custom", + "delineator", "docsify", "e.g.", "env", @@ -46,6 +47,7 @@ "specs", "tada", "tempy", + "typesync", "updtr", "v1", "walkthrough" diff --git a/__tests__/__mocks__/mockContext.ts b/__tests__/__mocks__/mockContext.ts index 03b527d..d7478e8 100644 --- a/__tests__/__mocks__/mockContext.ts +++ b/__tests__/__mocks__/mockContext.ts @@ -9,6 +9,8 @@ const noConfigSolidarity = { setSolidaritySettings: jest.fn(), updateRequirement: jest.fn(), updateVersions: jest.fn(() => Promise.resolve()), + getLineWithVersion: jest.fn(), + removeNonVersionCharacters: jest.fn(), } const mockContext = { @@ -16,6 +18,8 @@ const mockContext = { outputMode: undefined, system: { startTimer: jest.fn(() => jest.fn()), + run: jest.fn(() => '12'), + which: jest.fn(name => 'usr/local/bin/${name}'), }, template: { generate: jest.fn(), diff --git a/__tests__/command_helpers/checkCLI.ts b/__tests__/command_helpers/checkCLI.ts index 9f4cb8c..d8d7c40 100644 --- a/__tests__/command_helpers/checkCLI.ts +++ b/__tests__/command_helpers/checkCLI.ts @@ -9,6 +9,11 @@ const alwaysExistCLI = { binary: 'node', } +const badSemver = { + binary: 'node', + semver: 'wtfbbq!!!11', +} + const outOfDateCLI = { binary: 'node', semver: '10.99', @@ -24,6 +29,10 @@ test('fine on existing binary', async () => { expect(await checkCLI(alwaysExistCLI, context)).toBe(undefined) }) +test('errors with message when an improper semver is sent', async () => { + expect(await checkCLI(badSemver, context)).toBe(`Invalid semver rule ${badSemver.semver}`) +}) + test('returns message on improper version', async () => { solidarityExtension(context) context.solidarity.getVersion = () => '1' diff --git a/__tests__/command_helpers/getVersion.ts b/__tests__/command_helpers/getVersion.ts index c06a176..94e758d 100644 --- a/__tests__/command_helpers/getVersion.ts +++ b/__tests__/command_helpers/getVersion.ts @@ -13,7 +13,7 @@ describe('getVersion', () => { jasmine.DEFAULT_TIMEOUT_INTERVAL = 60000 }) - afterAll(function () { + afterAll(function() { // Fix timeout change jasmine.DEFAULT_TIMEOUT_INTERVAL = originalTimeout }) diff --git a/__tests__/command_helpers/quirksNodeModules.ts b/__tests__/command_helpers/quirksNodeModules.ts new file mode 100644 index 0000000..582b834 --- /dev/null +++ b/__tests__/command_helpers/quirksNodeModules.ts @@ -0,0 +1,32 @@ +const path = require('path') +const delineator = process.platform === 'win32' ? ';' : ':' +test('quirks moves node_modules to back', () => { + // key is that it has `node_modules` + path.sep + const injectedStuff = `node_modules${path.sep}testOnly` + // prepend to PATH + process.env.PATH = injectedStuff + delineator + process.env.PATH + const pathAsArray = process.env.PATH.split(delineator) + // Yup it is prepended to front + expect(pathAsArray[0]).toBe(injectedStuff) + // require mutates PATH + require('../../src/extensions/functions/quirksNodeModules') + const newPathAsArray = process.env.PATH.split(delineator) + // Not in the front + expect(newPathAsArray[0]).not.toBe(injectedStuff) + // still there though (moved to back) + expect(process.env.PATH.includes(injectedStuff)).toBeTruthy() +}) + +test('quirks does not move just any injected path to back', () => { + const injectedStuff = `taco${path.sep}testOnly` + // prepend to PATH + process.env.PATH = injectedStuff + delineator + process.env.PATH + const pathAsArray = process.env.PATH.split(delineator) + // Yup it is prepended to front + expect(pathAsArray[0]).toBe(injectedStuff) + // require does not mutate PATH this time + require('../../src/extensions/functions/quirksNodeModules') + const newPathAsArray = process.env.PATH.split(delineator) + // Not in the front + expect(newPathAsArray[0]).toBe(injectedStuff) +}) diff --git a/src/extensions/functions/checkCLI.ts b/src/extensions/functions/checkCLI.ts index 83a3f30..80f7007 100644 --- a/src/extensions/functions/checkCLI.ts +++ b/src/extensions/functions/checkCLI.ts @@ -2,6 +2,8 @@ import { SolidarityRunContext, CLIRule } from '../../types' module.exports = async (rule: CLIRule, context: SolidarityRunContext): Promise => { const { semver, solidarity } = context const binaryExists = require('./binaryExists') + // Node Modules do strange things + require('./quirksNodeModules') // First check for binary if (!binaryExists(rule.binary, context)) { diff --git a/src/extensions/functions/checkCLIForUpdates.ts b/src/extensions/functions/checkCLIForUpdates.ts index ef3034f..c1c4599 100644 --- a/src/extensions/functions/checkCLIForUpdates.ts +++ b/src/extensions/functions/checkCLIForUpdates.ts @@ -23,6 +23,7 @@ module.exports = async (rule: CLIRule, context: SolidarityRunContext): Promise