Skip to content
This repository has been archived by the owner on May 17, 2019. It is now read-only.

Commit

Permalink
Improve tests (#699)
Browse files Browse the repository at this point in the history
* Fix gql test regressions
Migrate i18n integration tests to fusion-cli

* fix lint and flow

* ignore fixture for flow in ci

* update lock file

* add other integration test
  • Loading branch information
lhorie authored Feb 13, 2019
1 parent 7f4b673 commit b34d877
Show file tree
Hide file tree
Showing 11 changed files with 1,590 additions and 3,668 deletions.
1 change: 1 addition & 0 deletions .flowconfig
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
.*/node_modules/.*[^(package)]\.json$
<PROJECT_ROOT>/dist/.*
.*/.fusion/.*
.*/i18n/fixture/.*

[include]
./src/
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,10 @@
"eslint-plugin-react": "^7.11.1",
"flow-bin": "^0.89.0",
"fusion-core": "1.10.2",
"fusion-plugin-i18n-react": "^1.2.1",
"fusion-plugin-i18n-react": "^1.2.3",
"fusion-plugin-react-router": "^1.4.2",
"fusion-plugin-universal-events": "^1.3.2",
"fusion-react": "1.3.4",
"fusion-react": "1.3.7",
"fusion-test-utils": "^1.3.0",
"fusion-tokens": "^1.1.1",
"globby": "^8.0.1",
Expand Down
165 changes: 165 additions & 0 deletions test/e2e/gql/__snapshots__/test.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`\`fusion build --production\` works with gql 1`] = `"{\\"kind\\":\\"Document\\",\\"definitions\\":[{\\"kind\\":\\"ObjectTypeDefinition\\",\\"name\\":{\\"kind\\":\\"Name\\",\\"value\\":\\"Query\\"},\\"interfaces\\":[],\\"directives\\":[],\\"fields\\":[{\\"kind\\":\\"FieldDefinition\\",\\"name\\":{\\"kind\\":\\"Name\\",\\"value\\":\\"user\\"},\\"arguments\\":[],\\"type\\":{\\"kind\\":\\"NamedType\\",\\"name\\":{\\"kind\\":\\"Name\\",\\"value\\":\\"User\\"}},\\"directives\\":[]}]},{\\"kind\\":\\"ObjectTypeDefinition\\",\\"name\\":{\\"kind\\":\\"Name\\",\\"value\\":\\"User\\"},\\"interfaces\\":[],\\"directives\\":[],\\"fields\\":[{\\"kind\\":\\"FieldDefinition\\",\\"name\\":{\\"kind\\":\\"Name\\",\\"value\\":\\"firstName\\"},\\"arguments\\":[],\\"type\\":{\\"kind\\":\\"NamedType\\",\\"name\\":{\\"kind\\":\\"Name\\",\\"value\\":\\"String\\"}},\\"directives\\":[]}]}],\\"loc\\":{\\"start\\":0,\\"end\\":62,\\"source\\":{\\"body\\":\\"type Query {\\\\n user: User\\\\n}\\\\n\\\\ntype User {\\\\n firstName: String\\\\n}\\",\\"name\\":\\"GraphQL request\\",\\"locationOffset\\":{\\"line\\":1,\\"column\\":1}}}}"`;

exports[`\`fusion build --production\` works with gql 2`] = `
Object {
"definitions": Array [
Object {
"directives": Array [],
"fields": Array [
Object {
"arguments": Array [],
"directives": Array [],
"kind": "FieldDefinition",
"name": Object {
"kind": "Name",
"value": "user",
},
"type": Object {
"kind": "NamedType",
"name": Object {
"kind": "Name",
"value": "User",
},
},
},
],
"interfaces": Array [],
"kind": "ObjectTypeDefinition",
"name": Object {
"kind": "Name",
"value": "Query",
},
},
Object {
"directives": Array [],
"fields": Array [
Object {
"arguments": Array [],
"directives": Array [],
"kind": "FieldDefinition",
"name": Object {
"kind": "Name",
"value": "firstName",
},
"type": Object {
"kind": "NamedType",
"name": Object {
"kind": "Name",
"value": "String",
},
},
},
],
"interfaces": Array [],
"kind": "ObjectTypeDefinition",
"name": Object {
"kind": "Name",
"value": "User",
},
},
],
"kind": "Document",
"loc": Object {
"end": 62,
"source": Object {
"body": "type Query {
user: User
}
type User {
firstName: String
}",
"locationOffset": Object {
"column": 1,
"line": 1,
},
"name": "GraphQL request",
},
"start": 0,
},
}
`;

exports[`\`fusion dev\` works with gql 1`] = `"{\\"kind\\":\\"Document\\",\\"definitions\\":[{\\"kind\\":\\"ObjectTypeDefinition\\",\\"name\\":{\\"kind\\":\\"Name\\",\\"value\\":\\"Query\\"},\\"interfaces\\":[],\\"directives\\":[],\\"fields\\":[{\\"kind\\":\\"FieldDefinition\\",\\"name\\":{\\"kind\\":\\"Name\\",\\"value\\":\\"user\\"},\\"arguments\\":[],\\"type\\":{\\"kind\\":\\"NamedType\\",\\"name\\":{\\"kind\\":\\"Name\\",\\"value\\":\\"User\\"}},\\"directives\\":[]}]},{\\"kind\\":\\"ObjectTypeDefinition\\",\\"name\\":{\\"kind\\":\\"Name\\",\\"value\\":\\"User\\"},\\"interfaces\\":[],\\"directives\\":[],\\"fields\\":[{\\"kind\\":\\"FieldDefinition\\",\\"name\\":{\\"kind\\":\\"Name\\",\\"value\\":\\"firstName\\"},\\"arguments\\":[],\\"type\\":{\\"kind\\":\\"NamedType\\",\\"name\\":{\\"kind\\":\\"Name\\",\\"value\\":\\"String\\"}},\\"directives\\":[]}]}],\\"loc\\":{\\"start\\":0,\\"end\\":62,\\"source\\":{\\"body\\":\\"type Query {\\\\n user: User\\\\n}\\\\n\\\\ntype User {\\\\n firstName: String\\\\n}\\",\\"name\\":\\"GraphQL request\\",\\"locationOffset\\":{\\"line\\":1,\\"column\\":1}}}}"`;

exports[`\`fusion dev\` works with gql 2`] = `
Object {
"definitions": Array [
Object {
"directives": Array [],
"fields": Array [
Object {
"arguments": Array [],
"directives": Array [],
"kind": "FieldDefinition",
"name": Object {
"kind": "Name",
"value": "user",
},
"type": Object {
"kind": "NamedType",
"name": Object {
"kind": "Name",
"value": "User",
},
},
},
],
"interfaces": Array [],
"kind": "ObjectTypeDefinition",
"name": Object {
"kind": "Name",
"value": "Query",
},
},
Object {
"directives": Array [],
"fields": Array [
Object {
"arguments": Array [],
"directives": Array [],
"kind": "FieldDefinition",
"name": Object {
"kind": "Name",
"value": "firstName",
},
"type": Object {
"kind": "NamedType",
"name": Object {
"kind": "Name",
"value": "String",
},
},
},
],
"interfaces": Array [],
"kind": "ObjectTypeDefinition",
"name": Object {
"kind": "Name",
"value": "User",
},
},
],
"kind": "Document",
"loc": Object {
"end": 62,
"source": Object {
"body": "type Query {
user: User
}
type User {
firstName: String
}",
"locationOffset": Object {
"column": 1,
"line": 1,
},
"name": "GraphQL request",
},
"start": 0,
},
}
`;
4 changes: 2 additions & 2 deletions test/e2e/gql/fixture/src/__tests__/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ import {test} from 'fusion-test-utils';
test('test with gql macro', () => {
const schema = gql('../schema.gql');
const query = gql('../query.gql');
expect(typeof schema).toEqual('Object');
expect(typeof query).toEqual('Object');
expect(typeof schema).toEqual('object');
expect(typeof query).toEqual('object');
});
23 changes: 4 additions & 19 deletions test/e2e/gql/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
const t = require('assert');
const path = require('path');
const request = require('request-promise');
const fs = require('fs');

const puppeteer = require('puppeteer');

Expand All @@ -25,20 +24,13 @@ test('`fusion dev` works with gql', async () => {
await app.setup();
const url = app.url();
try {
const expectedSchema = fs
.readFileSync(path.resolve(dir, 'src/schema.gql'))
.toString();
t.equal(
await request(`${url}/schema`),
expectedSchema,
'loads schema on server'
);
expect(await request(`${url}/schema`)).toMatchSnapshot();
const page = await app.browser().newPage();
await page.goto(`${url}/`, {waitUntil: 'load'});
const browserSchema = await page.evaluate(() => {
return typeof window !== undefined && window.schema; //eslint-disable-line
});
t.equal(browserSchema, expectedSchema, 'loads schema in the browser');
expect(browserSchema).toMatchSnapshot();
} catch (e) {
t.ifError(e);
}
Expand All @@ -52,14 +44,7 @@ test('`fusion build --production` works with gql', async () => {
env: Object.assign({}, process.env, {NODE_ENV: 'production'}),
});
try {
const expectedSchema = fs
.readFileSync(path.resolve(dir, 'src/schema.gql'))
.toString();
t.equal(
await request(`http://localhost:${port}/schema`),
expectedSchema,
'loads schema on server'
);
expect(await request(`http://localhost:${port}/schema`)).toMatchSnapshot();
browser = await puppeteer.launch({
args: ['--no-sandbox', '--disable-setuid-sandbox'],
});
Expand All @@ -68,7 +53,7 @@ test('`fusion build --production` works with gql', async () => {
const browserSchema = await page.evaluate(() => {
return typeof window !== undefined && window.schema; //eslint-disable-line
});
t.equal(browserSchema, expectedSchema, 'loads schema in the browser');
expect(browserSchema).toMatchSnapshot();
} catch (e) {
t.ifError(e);
}
Expand Down
9 changes: 9 additions & 0 deletions test/e2e/i18n/fixture/.fusionrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/** Copyright (c) 2018 Uber Technologies, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

module.exports = {
experimentalCompile: true,
};
1 change: 1 addition & 0 deletions test/e2e/i18n/fixture/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.fusion
33 changes: 33 additions & 0 deletions test/e2e/i18n/fixture/src/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/** Copyright (c) 2018 Uber Technologies, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
*/

import App from 'fusion-react';
import {FetchToken} from 'fusion-tokens';
import fetch from 'unfetch';
import {Locale} from 'locale';

import Plugin, {I18nToken, I18nLoaderToken} from 'fusion-plugin-i18n-react';

import Root from './root.js';

// Translation details
const data = {test: 'hello ${value}'};
const locale = new Locale('en-US');

export default () => {
const app = new App(Root);

app.register(I18nToken, Plugin);
__NODE__ &&
app.register(I18nLoaderToken, {
from: () => ({translations: data, locale: locale}),
});
__BROWSER__ && app.register(FetchToken, fetch);

return app;
};
17 changes: 17 additions & 0 deletions test/e2e/i18n/fixture/src/root.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/** Copyright (c) 2018 Uber Technologies, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
*/

import React from 'react';

import {Translate} from 'fusion-plugin-i18n-react';

export default (
<div>
<Translate id="test" data={{value: 'world'}} />
</div>
);
Loading

0 comments on commit b34d877

Please sign in to comment.