From 236a369867c1d4ff4e5825c759e3fd1ce6032c4b Mon Sep 17 00:00:00 2001 From: Martien Oranje Date: Sat, 30 Mar 2019 23:35:46 +0100 Subject: [PATCH] fix(project): tests failing due to faulty notifier reference --- src/project/__mocks__/references.ts | 33 +++++++++++++++++++++++++++++ src/project/index.ts | 2 +- src/project/references.ts | 7 ++++++ src/workflow/notification.ts | 7 ++---- test/error.spec.ts | 3 ++- test/integration.spec.ts | 1 + test/settings.spec.ts | 3 ++- 7 files changed, 48 insertions(+), 8 deletions(-) create mode 100644 src/project/__mocks__/references.ts diff --git a/src/project/__mocks__/references.ts b/src/project/__mocks__/references.ts new file mode 100644 index 00000000..5724f5b2 --- /dev/null +++ b/src/project/__mocks__/references.ts @@ -0,0 +1,33 @@ +/** + * A file path reference to settings.json. This is used to store workflow + * settings. + * + * @hidden + */ +export const SETTINGS_PATH = `${ + process.env.HOME +}/Library/Application Support/Alfred 3/Workflow Data/com.alfred-workflow-todoist/settings.json` + +/** + * A file path reference to the cache.json. This is used to store todoist APi + * call responses. + * + * @hidden + */ +export const CACHE_PATH = `${ + process.env.HOME +}/Library/Caches/com.runningwithcrayons.Alfred-3/Workflow Data/com.alfred-workflow-todoist/cache.json` + +/** + * A file path reference to package.josn. + * + * @hidden + */ +export const WORKFLOW_JSON = `${process.cwd()}/dist/workflow/workflow.json` + +/** + * A file path reference to package.josn. + * + * @hidden + */ +export const NOTIFIER_PATH = `${process.cwd()}/dist/workflow/notifier/terminal-notifier.app/Contents/MacOS/terminal-notifier` diff --git a/src/project/index.ts b/src/project/index.ts index 1f888888..b2cf9f46 100644 --- a/src/project/index.ts +++ b/src/project/index.ts @@ -1,5 +1,5 @@ export { AlfredError, handleError } from './error' -export { SETTINGS_PATH, CACHE_PATH, WORKFLOW_JSON } from './references' +export { SETTINGS_PATH, CACHE_PATH, WORKFLOW_JSON, NOTIFIER_PATH } from './references' export { Schema } from './settings-schema' export { FILES } from './files' export { verify, getSetting, getSettings, list, save } from './settings' diff --git a/src/project/references.ts b/src/project/references.ts index 81a419ed..b4fcb9b3 100644 --- a/src/project/references.ts +++ b/src/project/references.ts @@ -24,3 +24,10 @@ export const CACHE_PATH = `${ * @hidden */ export const WORKFLOW_JSON = `${process.cwd()}/workflow.json` + +/** + * A file path reference to package.josn. + * + * @hidden + */ +export const NOTIFIER_PATH = `${process.cwd()}/notifier/terminal-notifier.app/Contents/MacOS/terminal-notifier` diff --git a/src/workflow/notification.ts b/src/workflow/notification.ts index 8b7cb95d..78d06840 100644 --- a/src/workflow/notification.ts +++ b/src/workflow/notification.ts @@ -1,9 +1,6 @@ -import { AlfredError } from '@/project' -import omit from 'lodash.omit' -import notifier from 'node-notifier' -import open from 'opn' import compose from 'stampit' import { spawn } from 'child_process' +import { NOTIFIER_PATH } from '@/project' /** @hidden */ const NOTIFICATION_DEFAULTS: workflow.NotificationOptions = { @@ -55,7 +52,7 @@ function logError(error: project.AlfredError) { function notify(options: workflow.NotificationOptions) { let child = spawn( - './notifier/terminal-notifier.app/Contents/MacOS/terminal-notifier', + NOTIFIER_PATH, [ '-title', `"${options.title}"`, diff --git a/test/error.spec.ts b/test/error.spec.ts index c874e9d0..1ef8f16c 100644 --- a/test/error.spec.ts +++ b/test/error.spec.ts @@ -1,5 +1,6 @@ -import { AlfredError, handleError } from '@/project'; +import { AlfredError, handleError } from '@/project' +jest.mock('@/project/references') jest.mock('write-json-file', () => { return async (path: string, data: any) => { console.log(data) diff --git a/test/integration.spec.ts b/test/integration.spec.ts index e4f31093..160705fa 100644 --- a/test/integration.spec.ts +++ b/test/integration.spec.ts @@ -2,6 +2,7 @@ import './helpers/nock-requests' import { cache, Command } from '@/project' +jest.mock('@/project/references') jest.mock('@/project/files') jest.mock('write-json-file', () => { diff --git a/test/settings.spec.ts b/test/settings.spec.ts index 3f173a61..f6fdd657 100644 --- a/test/settings.spec.ts +++ b/test/settings.spec.ts @@ -1,5 +1,6 @@ -import { list, save } from '@/project'; +import { list, save } from '@/project' +jest.mock('@/project/references') jest.mock('@/project/files', () => ({ __esModule: true, FILES: { cache: [] }