-
Notifications
You must be signed in to change notification settings - Fork 133
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: remove test logic from lib (#171)
* refactor: remove test logic from lib * clean up test fixtures
- Loading branch information
Showing
8 changed files
with
322 additions
and
106 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
/** @type {import('ts-jest').JestConfigWithTsJest} **/ | ||
module.exports = { | ||
testEnvironment: 'node', | ||
transform: { | ||
'^.+.tsx?$': ['ts-jest', {}] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,33 @@ | ||
import os from 'node:os'; | ||
|
||
module.exports = { | ||
app: { | ||
getVersion: () => { | ||
return '1.2.3'; | ||
}, | ||
isReady: () => true, | ||
on: () => { | ||
/* no-op */ | ||
}, | ||
getAppPath: () => { | ||
return os.tmpdir(); | ||
}, | ||
isPackaged: true, | ||
}, | ||
autoUpdater: { | ||
checkForUpdates: () => { | ||
/* no-op */ | ||
}, | ||
on: () => { | ||
/* no-op */ | ||
}, | ||
setFeedURL: () => { | ||
/* no-op */ | ||
}, | ||
}, | ||
dialog: { | ||
showMessageBox: () => { | ||
/* no-op */ | ||
}, | ||
}, | ||
}; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import fs from 'node:fs'; | ||
import os from 'node:os'; | ||
import path from 'node:path'; | ||
|
||
import { updateElectronApp } from '..'; | ||
const repo = 'some-owner/some-repo'; | ||
|
||
jest.mock('electron'); | ||
|
||
beforeEach(() => { | ||
jest.useFakeTimers(); | ||
}); | ||
|
||
describe('updateElectronApp', () => { | ||
it('is a function', () => { | ||
expect(typeof updateElectronApp).toBe('function'); | ||
}); | ||
|
||
describe('repository', () => { | ||
const tmpdir = os.tmpdir(); | ||
const packageJson = path.join(tmpdir, 'package.json'); | ||
beforeAll(() => { | ||
fs.writeFileSync(packageJson, JSON.stringify({})); | ||
}); | ||
|
||
it('is required', () => { | ||
expect(() => { | ||
updateElectronApp(); | ||
}).toThrow("repo not found. Add repository string to your app's package.json file"); | ||
}); | ||
|
||
it('from opts', () => { | ||
updateElectronApp({ repo: 'foo/bar' }); | ||
}); | ||
|
||
it('from package.json', () => { | ||
fs.writeFileSync(packageJson, JSON.stringify({ repository: 'foo/bar' })); | ||
updateElectronApp(); | ||
}); | ||
|
||
afterAll(() => { | ||
fs.rmSync(packageJson); | ||
}); | ||
}); | ||
|
||
describe('host', () => { | ||
it('must a valid HTTPS URL', () => { | ||
expect(() => { | ||
updateElectronApp({ repo, host: 'http://example.com' }); | ||
}).toThrow('host must be a valid HTTPS URL'); | ||
}); | ||
}); | ||
|
||
describe('updateInterval', () => { | ||
it('must be 5 minutes or more', () => { | ||
expect(() => { | ||
updateElectronApp({ repo, updateInterval: '20 seconds' }); | ||
}).toThrow('updateInterval must be `5 minutes` or more'); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.