-
-
Notifications
You must be signed in to change notification settings - Fork 535
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(generic): add tests for lots of the utils
- Loading branch information
1 parent
93fb48f
commit d0962b9
Showing
14 changed files
with
196 additions
and
76 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { expect } from 'chai'; | ||
|
||
import config from '../../src/util/config'; | ||
|
||
describe('cross-process config', () => { | ||
it('should get all values as undefined initially', () => { | ||
expect(config.get('foobar')).to.equal(undefined); | ||
}); | ||
|
||
it('should set a value in the current process', () => { | ||
config.set('foobar', 'magical'); | ||
expect(config.get('foobar')).to.equal('magical'); | ||
}); | ||
|
||
it('should reset the value on process exit', () => { | ||
process.emit('exit'); | ||
expect(config.get('foobar')).to.equal(undefined); | ||
}); | ||
}); |
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,13 @@ | ||
import { expect } from 'chai'; | ||
|
||
import electronHostArch from '../../src/util/electron-host-arch'; | ||
|
||
describe('electron-host-arch', () => { | ||
if (process.arch !== 'arm') { | ||
describe('on non-arm systems', () => { | ||
it('should return the current arch', () => { | ||
expect(electronHostArch()).to.equal(process.arch); | ||
}); | ||
}); | ||
} | ||
}); |
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,50 @@ | ||
import { expect } from 'chai'; | ||
import fs from 'fs-promise'; | ||
import os from 'os'; | ||
import path from 'path'; | ||
|
||
import { ensureDirectory, ensureFile } from '../../src/util/ensure-output'; | ||
|
||
describe('ensure-output', () => { | ||
const tmpPath = path.resolve(os.tmpdir(), 'forge-ensure'); | ||
|
||
before(async () => { | ||
await fs.mkdirs(tmpPath); | ||
}); | ||
|
||
describe('ensureDirectory', () => { | ||
it('should delete the directory contents if it exists', async () => { | ||
await fs.mkdirs(path.resolve(tmpPath, 'foo')); | ||
fs.writeFileSync(path.resolve(tmpPath, 'foo', 'touchedFile')); | ||
expect(await fs.exists(path.resolve(tmpPath, 'foo', 'touchedFile'))).to.equal(true); | ||
await ensureDirectory(path.resolve(tmpPath, 'foo')); | ||
expect(await fs.exists(path.resolve(tmpPath, 'foo', 'touchedFile'))).to.equal(false); | ||
}); | ||
|
||
it('should create the directory if it does not exist', async () => { | ||
expect(await fs.exists(path.resolve(tmpPath, 'bar'))).to.equal(false); | ||
await ensureDirectory(path.resolve(tmpPath, 'bar')); | ||
expect(await fs.exists(path.resolve(tmpPath, 'bar'))).to.equal(true); | ||
}); | ||
}); | ||
|
||
describe('ensureFile', () => { | ||
it('should delete the file if it exists', async () => { | ||
await fs.mkdirs(path.resolve(tmpPath, 'foo')); | ||
fs.writeFileSync(path.resolve(tmpPath, 'foo', 'touchedFile')); | ||
expect(await fs.exists(path.resolve(tmpPath, 'foo', 'touchedFile'))).to.equal(true); | ||
await ensureFile(path.resolve(tmpPath, 'foo')); | ||
expect(await fs.exists(path.resolve(tmpPath, 'foo', 'touchedFile'))).to.equal(false); | ||
}); | ||
|
||
it('should create the containing directory if it does not exist', async () => { | ||
expect(await fs.exists(path.resolve(tmpPath, 'bar'))).to.equal(false); | ||
await ensureFile(path.resolve(tmpPath, 'bar', 'file')); | ||
expect(await fs.exists(path.resolve(tmpPath, 'bar'))).to.equal(true); | ||
}); | ||
}); | ||
|
||
afterEach(async () => { | ||
await fs.remove(tmpPath); | ||
}); | ||
}); |
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,38 @@ | ||
import { expect } from 'chai'; | ||
import path from 'path'; | ||
|
||
import findConfig from '../../src/util/forge-config'; | ||
|
||
const defaults = { | ||
make_targets: { | ||
win32: ['squirrel'], | ||
darwin: ['zip'], | ||
linux: ['deb', 'rpm'], | ||
mas: ['zip'], | ||
}, | ||
electronInstallerDMG: {}, | ||
electronPackagerConfig: {}, | ||
electronWinstallerConfig: {}, | ||
electronInstallerDebian: {}, | ||
electronInstallerRedhat: {}, | ||
}; | ||
|
||
describe('forge-config', () => { | ||
it('should resolve the object in package.json with defaults if one exists', async () => { | ||
expect(await findConfig(path.resolve(__dirname, '../fixture/dummy_app'))).to.be.deep.equal(Object.assign({}, defaults, { | ||
electronWinstallerConfig: { windows: 'magic' }, | ||
})); | ||
}); | ||
|
||
it('should resolve the JS file exports in config.forge points to a JS file', async () => { | ||
expect(JSON.parse(JSON.stringify(await findConfig(path.resolve(__dirname, '../fixture/dummy_js_conf'))))).to.be.deep.equal(Object.assign({}, defaults, { | ||
electronPackagerConfig: { foo: 'bar' }, | ||
})); | ||
}); | ||
|
||
it('should resolve the JS file exports in config.forge points to a JS file and maintain functions', async () => { | ||
const conf = await findConfig(path.resolve(__dirname, '../fixture/dummy_js_conf')); | ||
expect(conf.magicFn).to.be.a('function'); | ||
expect(conf.magicFn()).to.be.equal('magic result'); | ||
}); | ||
}); |
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,15 @@ | ||
import { expect } from 'chai'; | ||
|
||
import GitHub from '../../src/util/github'; | ||
|
||
describe('GitHub', () => { | ||
it('should read token from constructor', () => { | ||
expect(new GitHub('token1').token).to.equal('token1'); | ||
}); | ||
|
||
it('should fall back to token from environment', () => { | ||
process.env.GITHUB_TOKEN = 'abc123'; | ||
expect(new GitHub().token).to.equal('abc123'); | ||
delete process.env.GITHUB_TOKEN; | ||
}); | ||
}); |
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,10 @@ | ||
import path from 'path'; | ||
import { expect } from 'chai'; | ||
|
||
import readPackageJSON from '../../src/util/read-package-json'; | ||
|
||
describe('read-package-json', () => { | ||
it('should find a package.json file from the given directory', async () => { | ||
expect(await readPackageJSON(path.resolve(__dirname, '../..'))).to.deep.equal(require('../..//package.json')); | ||
}); | ||
}); |
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,16 @@ | ||
import { expect } from 'chai'; | ||
|
||
import requireSearch from '../../src/util/require-search'; | ||
import findConfig from '../../src/util/forge-config'; | ||
|
||
describe('require-search', () => { | ||
it('should resolve undefined if no file exists', () => { | ||
const resolved = requireSearch(__dirname, ['../../src/util/wizard-secrets']); | ||
expect(resolved).to.equal(undefined); | ||
}); | ||
|
||
it('should resolve a file if it exists', () => { | ||
const resolved = requireSearch(__dirname, ['../../src/util/forge-config']); | ||
expect(resolved).to.equal(findConfig); | ||
}); | ||
}); |
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,15 @@ | ||
import { expect } from 'chai'; | ||
import path from 'path'; | ||
|
||
import resolveDir from '../../src/util/resolve-dir'; | ||
|
||
describe('resolve-dir', () => { | ||
it('should return null if a valid dir can not be found', async () => { | ||
expect(await resolveDir('/foo/var/fake')).to.be.equal(null); | ||
}); | ||
|
||
it('should return a directory if it finds a node module', async () => { | ||
expect(await resolveDir(path.resolve(__dirname, '../fixture/dummy_app/foo'))).to.not.be.equal(null); | ||
expect(await resolveDir(path.resolve(__dirname, '../fixture/dummy_app/foo'))).to.be.equal(path.resolve(__dirname, '../fixture/dummy_app')); | ||
}); | ||
}); |
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 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.