Skip to content

Fix tests #77

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 29, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@
"babel-preset-stage-0": "^6.22.0",
"eslint": "^3.18.0",
"eslint-plugin-import": "^2.2.0",
"jest": "^19.0.2",
"jest": "^23",
"tmp": "^0.0.31"
},
"dependencies": {
"@api-platform/api-doc-parser": "^0.2",
"@api-platform/api-doc-parser": "^0.4",
"babel-runtime": "^6.23.0",
"chalk": "^2.1.0",
"commander": "^2.9.0",
Expand Down
27 changes: 15 additions & 12 deletions src/generators/AdminOnRestGenerator.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import fs from 'fs';
import tmp from 'tmp';
import AdminOnRestGenerator from './AdminOnRestGenerator';


test('Generate a Admin On Rest app', () => {
const generator = new AdminOnRestGenerator({hydraPrefix: 'hydra:', templateDirectory: `${__dirname}/../../templates`});
const tmpobj = tmp.dirSync({unsafeCleanup: true});
Expand All @@ -18,8 +17,8 @@ test('Generate a Admin On Rest app', () => {
description: 'An URL'
})];
const resource = new Resource('abc', 'http://example.com/foos', {
id: 'foo',
title: 'Foo',
id: 'abc',
title: 'abc',
readableFields: fields,
writableFields: fields
});
Expand All @@ -30,15 +29,19 @@ test('Generate a Admin On Rest app', () => {
});
generator.generate(api, resource, tmpobj.name);

expect(fs.existsSync(tmpobj.name+'/config/_entrypoint.js'), true);

expect(fs.existsSync(tmpobj.name+'/components/abc.js'), true);

expect(fs.existsSync(tmpobj.name+'/config/abc.js'), true);

expect(fs.existsSync(tmpobj.name+'/resources/abc.js'), true);

expect(fs.existsSync(tmpobj.name+'/resource-import.js'), true);
[
'/config/_entrypoint.js',
'/resources/abc.js',
'/resource-import.js',
].forEach(file => expect(fs.existsSync(tmpobj.name+file)).toBe(true));

[
'/components/abc.js',
'/config/abc.js',
].forEach(file => {
expect(fs.existsSync(tmpobj.name+file)).toBe(true)
expect(fs.readFileSync(tmpobj.name+file, 'utf8')).toMatch(/bar/);
});

tmpobj.removeCallback();
});
66 changes: 40 additions & 26 deletions src/generators/ReactGenerator.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,22 @@ import fs from 'fs';
import tmp from 'tmp';
import ReactGenerator from './ReactGenerator';


test('Generate a React app', () => {
const generator = new ReactGenerator({hydraPrefix: 'hydra:', templateDirectory: `${__dirname}/../../templates`});
const tmpobj = tmp.dirSync({unsafeCleanup: true});

const fields = [new Field('bar', {
id: 'http://schema.org/url',
range: 'http://www.w3.org/2001/XMLSchema#string',
reference: null,
required: true,
description: 'An URL'
})];
const fields = [
new Field('bar', {
id: 'http://schema.org/url',
range: 'http://www.w3.org/2001/XMLSchema#string',
reference: null,
required: true,
description: 'An URL'
}),
];
const resource = new Resource('abc', 'http://example.com/foos', {
id: 'foo',
title: 'Foo',
id: 'abc',
title: 'abc',
readableFields: fields,
writableFields: fields
});
Expand All @@ -30,26 +31,39 @@ test('Generate a React app', () => {
});
generator.generate(api, resource, tmpobj.name);

expect(fs.existsSync(tmpobj.name+'/utils/fetch.js'), true);
expect(fs.existsSync(tmpobj.name+'/utils/helpers.js'), true);
[
'/utils/fetch.js',
'/utils/helpers.js',
'/config/_entrypoint.js',

'/actions/abc/create.js',
'/actions/abc/delete.js',
'/actions/abc/list.js',
'/actions/abc/show.js',
'/actions/abc/update.js',

expect(fs.existsSync(tmpobj.name+'/config/_entrypoint.js'), true);
'/components/abc/index.js',
'/components/abc/Create.js',
'/components/abc/Update.js',

expect(fs.existsSync(tmpobj.name+'/actions/abc/create.js'), true);
expect(fs.existsSync(tmpobj.name+'/actions/abc/delete.js'), true);
expect(fs.existsSync(tmpobj.name+'/actions/abc/list.js'), true);
expect(fs.existsSync(tmpobj.name+'/actions/abc/update.js'), true);
'/routes/abc.js',

expect(fs.existsSync(tmpobj.name+'/components/abc/Create.js'), true);
expect(fs.existsSync(tmpobj.name+'/components/abc/Form.js'), true);
expect(fs.existsSync(tmpobj.name+'/components/abc/List.js'), true);
expect(fs.existsSync(tmpobj.name+'/components/abc/Update.js'), true);
'/reducers/abc/create.js',
'/reducers/abc/delete.js',
'/reducers/abc/index.js',
'/reducers/abc/list.js',
'/reducers/abc/show.js',
'/reducers/abc/update.js',
].forEach(file => expect(fs.existsSync(tmpobj.name+file)).toBe(true));

expect(fs.existsSync(tmpobj.name+'/reducers/abc/create.js'), true);
expect(fs.existsSync(tmpobj.name+'/reducers/abc/delete.js'), true);
expect(fs.existsSync(tmpobj.name+'/reducers/abc/index.js'), true);
expect(fs.existsSync(tmpobj.name+'/reducers/abc/list.js'), true);
expect(fs.existsSync(tmpobj.name+'/reducers/abc/update.js'), true);
[
'/components/abc/Form.js',
'/components/abc/List.js',
'/components/abc/Show.js',
].forEach(file => {
expect(fs.existsSync(tmpobj.name+file)).toBe(true);
expect(fs.readFileSync(tmpobj.name+file, 'utf8')).toMatch(/bar/);
});

tmpobj.removeCallback();
});
44 changes: 27 additions & 17 deletions src/generators/ReactNativeGenerator.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ test('Generate a React app', () => {
description: 'An URL'
})];
const resource = new Resource('abc', 'http://example.com/foos', {
id: 'foo',
title: 'Foo',
id: 'abc',
title: 'abc',
readableFields: fields,
writableFields: fields
});
Expand All @@ -30,25 +30,35 @@ test('Generate a React app', () => {
});
generator.generate(api, resource, tmpobj.name);

expect(fs.existsSync(tmpobj.name+'/utils/fetch.js'), true);
[
'/utils/fetch.js',
'/config/_entrypoint.js',

expect(fs.existsSync(tmpobj.name+'/config/_entrypoint.js'), true);
'/actions/abc/create.js',
'/actions/abc/delete.js',
'/actions/abc/list.js',
'/actions/abc/show.js',
'/actions/abc/update.js',

expect(fs.existsSync(tmpobj.name+'/actions/abc/create.js'), true);
expect(fs.existsSync(tmpobj.name+'/actions/abc/delete.js'), true);
expect(fs.existsSync(tmpobj.name+'/actions/abc/list.js'), true);
expect(fs.existsSync(tmpobj.name+'/actions/abc/update.js'), true);
'/components/abc/Create.js',
'/components/abc/Update.js',

expect(fs.existsSync(tmpobj.name+'/components/abc/Create.js'), true);
expect(fs.existsSync(tmpobj.name+'/components/abc/Form.js'), true);
expect(fs.existsSync(tmpobj.name+'/components/abc/List.js'), true);
expect(fs.existsSync(tmpobj.name+'/components/abc/Update.js'), true);
'/reducers/abc/create.js',
'/reducers/abc/delete.js',
'/reducers/abc/index.js',
'/reducers/abc/list.js',
'/reducers/abc/show.js',
'/reducers/abc/update.js',
].forEach(file => expect(fs.existsSync(tmpobj.name+file)).toBe(true));

expect(fs.existsSync(tmpobj.name+'/reducers/abc/create.js'), true);
expect(fs.existsSync(tmpobj.name+'/reducers/abc/delete.js'), true);
expect(fs.existsSync(tmpobj.name+'/reducers/abc/index.js'), true);
expect(fs.existsSync(tmpobj.name+'/reducers/abc/list.js'), true);
expect(fs.existsSync(tmpobj.name+'/reducers/abc/update.js'), true);
[
'/components/abc/Form.js',
'/components/abc/List.js',
'/components/abc/Show.js',
].forEach(file => {
expect(fs.existsSync(tmpobj.name+file)).toBe(true);
expect(fs.readFileSync(tmpobj.name+file, 'utf8')).toMatch(/bar/);
});

tmpobj.removeCallback();
});
5 changes: 2 additions & 3 deletions src/generators/TypescriptInterfaceGenerator.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import fs from 'fs';
import tmp from 'tmp';
import TypescriptInterfaceGenerator from './TypescriptInterfaceGenerator';


test('Generate a typescript interface', () => {
const generator = new TypescriptInterfaceGenerator({templateDirectory: `${__dirname}/../../templates`});
const tmpobj = tmp.dirSync({unsafeCleanup: true});
Expand Down Expand Up @@ -40,9 +39,9 @@ test('Generate a typescript interface', () => {
});
generator.generate(api, resource, tmpobj.name);

expect(fs.existsSync(tmpobj.name+'/interfaces/foo.ts'), true);
expect(fs.existsSync(tmpobj.name+'/interfaces/foo.ts')).toBe(true);

const res = `interface Foo {
const res = `interface Foo {
'@id'?: string;
id: string;
foo: any;
Expand Down
Loading