Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
37 changed files
with
715 additions
and
360 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 |
---|---|---|
@@ -1,13 +1,9 @@ | ||
/** Ava configuration. */ | ||
/** | ||
* Ava configuration. | ||
*/ | ||
// eslint-disable-next-line import/no-default-export | ||
export default { | ||
extensions: ['js', 'ts', 'tsx'], | ||
files: ['src/**/{*.,}test.*'], | ||
require: [ | ||
'esm', | ||
'tsconfig-paths/register', | ||
'ts-node/register/transpile-only', | ||
'source-map-support/register', | ||
'browser-env/register', | ||
], | ||
require: ['./test/setup'], | ||
} |
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 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,9 @@ | ||
import test from 'ava' | ||
import React from 'react' | ||
import {create} from 'react-test-renderer' | ||
|
||
test('render', async t => { | ||
const {Header} = await import('.') | ||
const component = create(<Header title="Title" />) | ||
t.snapshot(component.toJSON()) | ||
}) |
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,26 @@ | ||
# Snapshot report for `src/common/components/header/test.tsx` | ||
|
||
The actual snapshot is saved in `test.tsx.snap`. | ||
|
||
Generated by [AVA](https://avajs.dev). | ||
|
||
## render | ||
|
||
> Snapshot 1 | ||
<header | ||
className="sc-AxirZ gELXlJ" | ||
> | ||
<div | ||
className="sc-AxjAm lkPSa-D" | ||
> | ||
<h1> | ||
<a | ||
className="sc-AxiKw iaIeKE" | ||
href="/" | ||
> | ||
Title | ||
</a> | ||
</h1> | ||
</div> | ||
</header> |
Binary file not shown.
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,22 @@ | ||
import * as IO from 'io-ts' | ||
import {useMemo} from 'react' | ||
import {decode} from '../../util/io' | ||
|
||
/** | ||
* Decode wrapped with memoization. | ||
* @param type IO type | ||
* @param value Value to attempt to decode | ||
* @param fallback Optional fallback value to avoid error thrown | ||
* @return Successful value | ||
*/ | ||
export const useDecode: typeof decode = (type, value, fallback) => | ||
useMemo(() => decode(type, value, fallback), [type, value, fallback]) | ||
|
||
/** | ||
* Encode wrapped with memoization. | ||
* @param type IO type | ||
* @param value Value to encode | ||
* @return Successful value | ||
*/ | ||
export const useEncode = <A, O>(type: IO.Encoder<A, O>, value: A) => | ||
useMemo(() => type.encode(value), [type, value]) |
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,25 @@ | ||
import {isRight} from 'fp-ts/es6/Either' | ||
import * as IO from 'io-ts' | ||
import {reporter} from 'io-ts-reporters' | ||
|
||
/** | ||
* Decode wrapped with memoization. | ||
* @param type IO type | ||
* @param value Value to attempt to decode | ||
* @param fallback Optional fallback value to avoid error thrown | ||
* @return Successful value | ||
*/ | ||
export const decode = <A>( | ||
type: IO.Decoder<unknown, A>, | ||
value: unknown, | ||
fallback?: A, | ||
) => { | ||
const validation = type.decode(value) | ||
if (!isRight(validation)) { | ||
if (fallback === undefined) { | ||
throw new Error(reporter(validation).join('\n')) | ||
} | ||
return fallback | ||
} | ||
return validation.right | ||
} |
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,18 @@ | ||
import * as IO from 'io-ts' | ||
import test from 'ava' | ||
|
||
test('decode', async t => { | ||
const {decode} = await import('.') | ||
t.is(decode(IO.number, 1), 1) | ||
}) | ||
|
||
test('decode with fallback', async t => { | ||
const {decode} = await import('.') | ||
t.is(decode(IO.number, 'a', 1), 1) | ||
}) | ||
|
||
test('decode with error', async t => { | ||
const {decode} = await import('.') | ||
const e = t.throws(() => decode(IO.number, 'a')) | ||
t.is(e.message, 'Expecting number but instead got: "a"') | ||
}) |
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,47 @@ | ||
import test from 'ava' | ||
import React from 'react' | ||
import {create} from 'react-test-renderer' | ||
|
||
test('render with fixed Sharp image', async t => { | ||
const {GatsbyImage} = await import('.') | ||
const data = { | ||
childImageSharp: { | ||
fixed: { | ||
height: 100, | ||
src: '/some/url', | ||
srcSet: '/some/url 100w, /another/url 200w', | ||
width: 100, | ||
}, | ||
}, | ||
url: '/some/url', | ||
} | ||
const component = create(<GatsbyImage data={data} />) | ||
t.snapshot(component.toJSON()) | ||
}) | ||
|
||
test('render with fluid Sharp image', async t => { | ||
const {GatsbyImage} = await import('.') | ||
const data = { | ||
childImageSharp: { | ||
fluid: { | ||
aspectRatio: 1, | ||
presentationWidth: 100, | ||
sizes: '(max-width: 50px) 50vw, 100px', | ||
src: '/some/url', | ||
srcSet: '/some/url 100w, /another/url 200w', | ||
}, | ||
}, | ||
url: '/some/url', | ||
} | ||
const component = create(<GatsbyImage data={data} />) | ||
t.snapshot(component.toJSON()) | ||
}) | ||
|
||
test('render with no Sharp image', async t => { | ||
const {GatsbyImage} = await import('.') | ||
const data = { | ||
url: '/some/url', | ||
} | ||
const component = create(<GatsbyImage data={data} />) | ||
t.snapshot(component.toJSON()) | ||
}) |
Oops, something went wrong.