-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change format handling and add tests (#1)
- Loading branch information
Showing
10 changed files
with
1,034 additions
and
60 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,8 +5,8 @@ | |
"author": "Sebastian Müller <[email protected]>", | ||
"main": "src/plugin.js", | ||
"scripts": { | ||
"test": "jest test", | ||
"test:cover": "jest test --coverage", | ||
"test": "yarn lint && jest test", | ||
"test:cover": "yarn lint && jest test --coverage", | ||
"coveralls": "cat ./coverage/lcov.info | coveralls", | ||
"lint": "standard | snazzy" | ||
}, | ||
|
@@ -27,6 +27,9 @@ | |
"output" | ||
], | ||
"dependencies": { | ||
"jasmine-data-provider": "^2.2.0", | ||
"nativefier": "^7.4.0", | ||
"sinon": "^2.3.6", | ||
"tomlify-j0.4": "^2.0.0", | ||
"yamljs": "^0.3.0" | ||
}, | ||
|
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 was deleted.
Oops, something went wrong.
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
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,36 @@ | ||
'use strict' | ||
|
||
const using = require('jasmine-data-provider') | ||
const File = require('../src/file.js') | ||
|
||
describe('File', () => { | ||
describe('Constructor', () => { | ||
it('pass path', () => { | ||
const f = new File(__dirname) | ||
expect(f.path).toBe(__dirname) | ||
}) | ||
}) | ||
|
||
describe('Format', () => { | ||
using( | ||
[ | ||
{file: 'test.yaml', valid: true, type: 'yaml', data: `foo: bar\n`}, | ||
{file: 'test.yml', valid: true, type: 'yaml', data: `foo: bar\n`}, | ||
{file: 'test.json', valid: true, type: 'json', data: `{\n "foo": "bar"\n}`}, | ||
{file: 'test.toml', valid: true, type: 'toml', data: 'foo = "bar"'}, | ||
{file: 'test.zip', valid: false} | ||
], | ||
data => { | ||
it('detects' + (data.valid ? ' valid ' : ' invalid ') + data.file, () => { | ||
const f = new File(data.file) | ||
|
||
if (data.valid) { | ||
expect(f.format({ foo: 'bar' })).toBe(data.data) | ||
} else { | ||
expect(() => f.format()).toThrow() | ||
} | ||
}) | ||
} | ||
) | ||
}) | ||
}) |
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,7 +1,74 @@ | ||
'use strict' | ||
|
||
const sinon = require('sinon') | ||
const Plugin = require('../') | ||
|
||
it('Works', () => { | ||
expect(new Plugin({})).toHaveProperty('serverless') | ||
describe('Plugin', () => { | ||
let providerMock = null | ||
let getProvider = null | ||
let provider = { | ||
request: () => true, | ||
sdk: { | ||
VERSION: '2.21.0' | ||
} | ||
} | ||
|
||
beforeEach(() => { | ||
providerMock = sinon.mock(provider) | ||
getProvider = sinon.stub().returns(provider) | ||
}) | ||
|
||
afterEach(() => { | ||
providerMock.restore() | ||
}) | ||
|
||
describe('Configuration', () => { | ||
it('hasHandler', () => { | ||
const config = { | ||
cli: { log: () => {} }, | ||
region: 'us-east-1', | ||
service: { | ||
provider: { | ||
name: 'aws' | ||
}, | ||
custom: { | ||
output: { | ||
handler: 'foo/bar.baz' | ||
} | ||
} | ||
}, | ||
getProvider | ||
} | ||
|
||
const test = new Plugin(config) | ||
|
||
expect(test.hasHandler()).toBe(true) | ||
expect(test.hasFile()).toBe(false) | ||
}) | ||
}) | ||
|
||
describe('Configuration', () => { | ||
it('hasFile', () => { | ||
const config = { | ||
cli: { log: () => {} }, | ||
region: 'us-east-1', | ||
service: { | ||
provider: { | ||
name: 'aws' | ||
}, | ||
custom: { | ||
output: { | ||
file: './foo/bar.toml' | ||
} | ||
} | ||
}, | ||
getProvider | ||
} | ||
|
||
const test = new Plugin(config) | ||
|
||
expect(test.hasHandler()).toBe(false) | ||
expect(test.hasFile()).toBe(true) | ||
}) | ||
}) | ||
}) |
Oops, something went wrong.