diff --git a/test/load/__fixtures__/simple-pages/bar/baz.js b/test/__fixtures__/custom-website/pages/bar/baz.js similarity index 100% rename from test/load/__fixtures__/simple-pages/bar/baz.js rename to test/__fixtures__/custom-website/pages/bar/baz.js diff --git a/test/load/__fixtures__/simple-pages/foo.js b/test/__fixtures__/custom-website/pages/foo.js similarity index 100% rename from test/load/__fixtures__/simple-pages/foo.js rename to test/__fixtures__/custom-website/pages/foo.js diff --git a/test/load/__fixtures__/simple-pages/foo/index.js b/test/__fixtures__/custom-website/pages/foo/index.js similarity index 100% rename from test/load/__fixtures__/simple-pages/foo/index.js rename to test/__fixtures__/custom-website/pages/foo/index.js diff --git a/test/load/__fixtures__/simple-pages/index.js b/test/__fixtures__/custom-website/pages/index.js similarity index 100% rename from test/load/__fixtures__/simple-pages/index.js rename to test/__fixtures__/custom-website/pages/index.js diff --git a/test/__fixtures__/custom-website/siteConfig.js b/test/__fixtures__/custom-website/siteConfig.js new file mode 100644 index 0000000000..3c5b2a6f42 --- /dev/null +++ b/test/__fixtures__/custom-website/siteConfig.js @@ -0,0 +1,7 @@ +module.exports = { + title: 'Sakura', + tagline: 'This is not an ordinary site', + organizationName: 'endiliey', + projectName: 'sakura', + baseUrl: '/sakura/' +}; diff --git a/test/load/__fixtures__/simple-docs/foo/bar.md b/test/__fixtures__/docs/foo/bar.md similarity index 100% rename from test/load/__fixtures__/simple-docs/foo/bar.md rename to test/__fixtures__/docs/foo/bar.md diff --git a/test/load/__fixtures__/simple-docs/foo/baz.md b/test/__fixtures__/docs/foo/baz.md similarity index 100% rename from test/load/__fixtures__/simple-docs/foo/baz.md rename to test/__fixtures__/docs/foo/baz.md diff --git a/test/load/__fixtures__/simple-docs/hello.md b/test/__fixtures__/docs/hello.md similarity index 100% rename from test/load/__fixtures__/simple-docs/hello.md rename to test/__fixtures__/docs/hello.md diff --git a/test/__fixtures__/simple-website/pages/bar/baz.js b/test/__fixtures__/simple-website/pages/bar/baz.js new file mode 100644 index 0000000000..75a8c70015 --- /dev/null +++ b/test/__fixtures__/simple-website/pages/bar/baz.js @@ -0,0 +1,3 @@ +import React from 'react'; + +export default () =>
Baz
; diff --git a/test/__fixtures__/simple-website/pages/foo.js b/test/__fixtures__/simple-website/pages/foo.js new file mode 100644 index 0000000000..3b52ec615c --- /dev/null +++ b/test/__fixtures__/simple-website/pages/foo.js @@ -0,0 +1,3 @@ +import React from 'react'; + +export default () =>
Foo
; diff --git a/test/__fixtures__/simple-website/pages/foo/index.js b/test/__fixtures__/simple-website/pages/foo/index.js new file mode 100644 index 0000000000..5faf67ae13 --- /dev/null +++ b/test/__fixtures__/simple-website/pages/foo/index.js @@ -0,0 +1,3 @@ +import React from 'react'; + +export default () =>
Foo in subfolder
; diff --git a/test/__fixtures__/simple-website/pages/index.js b/test/__fixtures__/simple-website/pages/index.js new file mode 100644 index 0000000000..13063810a7 --- /dev/null +++ b/test/__fixtures__/simple-website/pages/index.js @@ -0,0 +1,3 @@ +import React from 'react'; + +export default () =>
Index
; diff --git a/test/__fixtures__/simple-website/siteConfig.js b/test/__fixtures__/simple-website/siteConfig.js new file mode 100644 index 0000000000..e64b9989cf --- /dev/null +++ b/test/__fixtures__/simple-website/siteConfig.js @@ -0,0 +1,7 @@ +module.exports = { + title: 'Hello', + tagline: 'Hello World', + organizationName: 'endiliey', + projectName: 'hello', + baseUrl: '/' +}; diff --git a/test/loadSetup.js b/test/loadSetup.js new file mode 100644 index 0000000000..2aa6995b88 --- /dev/null +++ b/test/loadSetup.js @@ -0,0 +1,19 @@ +import path from 'path'; +import load from '@lib/load'; + +// Helper methods to setup dummy/ fake projects +const loadSetup = async name => { + const simpleWebsite = path.join(__dirname, '__fixtures__', 'simple-website'); + const customWebsite = path.join(__dirname, '__fixtures__', 'custom-website'); + + switch (name) { + case 'simple': + return await load(simpleWebsite); + case 'custom': + return await load(customWebsite); + default: + return {}; + } +}; + +export default loadSetup; diff --git a/test/webpack/index.test.js b/test/webpack/index.test.js new file mode 100644 index 0000000000..d9fe538fe3 --- /dev/null +++ b/test/webpack/index.test.js @@ -0,0 +1,48 @@ +import webpack from 'webpack'; +import path from 'path'; +import createBaseConfig from '@lib/webpack/base'; +import createDevConfig from '@lib/webpack/dev'; +import createProdConfig from '@lib/webpack/prod'; +import loadSetup from '../loadSetup'; + +// webpack compiler helper function +function compile(config) { + return new Promise((resolve, reject) => { + webpack(config, (err, stats) => { + if (err || stats.hasErrors()) { + reject(new Error(`Failed to compile with errors`)); + } + resolve('Compiled successfully'); + }); + }); +} + +describe('webpack', () => { + test('dev simple', async () => { + console.log = jest.fn(); + const props = await loadSetup('simple'); + const config = createDevConfig(props).toConfig(); + return expect(compile(config)).resolves.toBe('Compiled successfully'); + }); + + test('dev custom', async () => { + console.log = jest.fn(); + const props = await loadSetup('custom'); + const config = createDevConfig(props).toConfig(); + return expect(compile(config)).resolves.toBe('Compiled successfully'); + }); + + test('prod simple', async () => { + console.log = jest.fn(); + const props = await loadSetup('simple'); + const config = createProdConfig(props).toConfig(); + return expect(compile(config)).resolves.toBe('Compiled successfully'); + }); + + test('prod custom', async () => { + console.log = jest.fn(); + const props = await loadSetup('custom'); + const config = createProdConfig(props).toConfig(); + return expect(compile(config)).resolves.toBe('Compiled successfully'); + }); +});