Skip to content
This repository has been archived by the owner on Mar 13, 2023. It is now read-only.

Commit

Permalink
fix(project): tests failing due to faulty notifier reference
Browse files Browse the repository at this point in the history
  • Loading branch information
moranje committed Mar 30, 2019
1 parent e9f4262 commit 236a369
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 8 deletions.
33 changes: 33 additions & 0 deletions src/project/__mocks__/references.ts
Original file line number Diff line number Diff line change
@@ -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`
2 changes: 1 addition & 1 deletion src/project/index.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down
7 changes: 7 additions & 0 deletions src/project/references.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`
7 changes: 2 additions & 5 deletions src/workflow/notification.ts
Original file line number Diff line number Diff line change
@@ -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 = {
Expand Down Expand Up @@ -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}"`,
Expand Down
3 changes: 2 additions & 1 deletion test/error.spec.ts
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
1 change: 1 addition & 0 deletions test/integration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
3 changes: 2 additions & 1 deletion test/settings.spec.ts
Original file line number Diff line number Diff line change
@@ -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: [] }
Expand Down

0 comments on commit 236a369

Please sign in to comment.