Skip to content

Commit

Permalink
test subpath image includes
Browse files Browse the repository at this point in the history
  • Loading branch information
kommander committed Apr 28, 2017
1 parent d7dc442 commit 1cc4cfe
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 14 deletions.
10 changes: 3 additions & 7 deletions extensions/md/index.js
@@ -1,5 +1,4 @@
const fs = require('fs');
const marked = require('marked');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const path = require('path');
const hogan = require('hogan.js');
Expand Down Expand Up @@ -149,7 +148,7 @@ module.exports = (aden) => {
}
});

aden.hook('post:apply', ({ page, webpackConfigs, webpackEntry }) => {
aden.hook('post:apply', ({ webpackConfigs }) => {
webpackConfigs[0].module.rules.push({
test: /\.md$/,
use: [
Expand All @@ -159,18 +158,15 @@ module.exports = (aden) => {
},
{
loader: require.resolve('markdown-loader'),
// TODO: take marked options from .server config md key
// options: {},
},
],
});
});

aden.hook('apply', ({ page, webpackConfigs, webpackEntry }) => {
aden.hook('apply', ({ page, webpackConfigs }) => {
if (page.key.mdIndex.value || page.key.mdFiles.value.length > 0) {
// if (page.key.mdIndex.value) {
// webpackEntry.push(page.key.mdIndex.resolved);
// }

const chunks = ['global', page.entryName];

if (page.commons) {
Expand Down
3 changes: 3 additions & 0 deletions test/data/md/sub/index.md
@@ -1 +1,4 @@
# Sub Page

![test](../test2.png)
![test](./sub-test.png)
Binary file added test/data/md/sub/sub-test.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added test/data/md/test2.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
30 changes: 30 additions & 0 deletions test/integration/md.dev.spec.js
Expand Up @@ -106,4 +106,34 @@ describe('MD Markdown Extension Dev', () => {
});
});
});

she('includes images required from sub path in the build', (done) => {
aden({ dev: true })
.init(path.resolve(__dirname, '../tmpdata/md'))
.then((an) => an.run('dev'))
.then((an) => {
request(an.app)
.get('/images/test2.png')
.end((err, res) => {
if (err) done(err);
expect(res.status).toMatch(200);
an.shutdown(done);
});
});
});

she('includes images from sub path in the build', (done) => {
aden({ dev: true })
.init(path.resolve(__dirname, '../tmpdata/md'))
.then((an) => an.run('dev'))
.then((an) => {
request(an.app)
.get('/images/sub-test.png')
.end((err, res) => {
if (err) done(err);
expect(res.status).toMatch(200);
an.shutdown(done);
});
});
});
});
62 changes: 55 additions & 7 deletions test/integration/md.prod.spec.js
Expand Up @@ -15,7 +15,8 @@ describe('MD Markdown Extension Prod', () => {
.expect(200, () => {
an.shutdown(done);
});
});
})
.catch(done);
});

she('delivers index.md at root path', (done) => {
Expand All @@ -31,7 +32,8 @@ describe('MD Markdown Extension Prod', () => {
expect(res.text).toMatch(/Hello marked/ig);
an.shutdown(done);
});
});
})
.catch(done);
});

she('delivers index.md at sub path', (done) => {
Expand All @@ -47,7 +49,8 @@ describe('MD Markdown Extension Prod', () => {
expect(res.text).toMatch(/Sub Page/ig);
an.shutdown(done);
});
});
})
.catch(done);
});

she('delivers additional md files at page path', (done) => {
Expand All @@ -63,7 +66,8 @@ describe('MD Markdown Extension Prod', () => {
expect(res.text).toMatch(/Just a file/ig);
an.shutdown(done);
});
});
})
.catch(done);
});

she('delivers additional md files at page sub path', (done) => {
Expand All @@ -79,7 +83,8 @@ describe('MD Markdown Extension Prod', () => {
expect(res.text).toMatch(/yet another page/ig);
an.shutdown(done);
});
});
})
.catch(done);
});

she('wraps md in given layout (layout.default.html|hbs|md)', (done) => {
Expand All @@ -95,7 +100,8 @@ describe('MD Markdown Extension Prod', () => {
expect(res.text).toMatch(/id="wrapper"/ig);
an.shutdown(done);
});
});
})
.catch(done);
});

she('includes images in the build', (done) => {
Expand All @@ -113,6 +119,48 @@ describe('MD Markdown Extension Prod', () => {
expect(res.status).toMatch(200);
an.shutdown(done);
});
});
})
.catch(done);
});

she('includes images required from sub path in the build', (done) => {
aden()
.init(path.resolve(__dirname, '../tmpdata/md'))
.then((an) => an.run('build'))
.then((an) => an.run('production'))
.then((an) => {
// In production images use a hash only name,
// where images with same content become the same resource
const fileName = an.webpackStats[0].assets
.filter((asset) => asset.name.match(/^images/))[0].name;
request(an.app)
.get(`/${fileName}`)
.end((err, res) => {
if (err) done(err);
expect(res.status).toMatch(200);
an.shutdown(done);
});
})
.catch(done);
});

she('includes images from sub path in the build', (done) => {
aden()
.init(path.resolve(__dirname, '../tmpdata/md'))
.then((an) => an.run('build'))
.then((an) => an.run('production'))
.then((an) => {
// resolve sub-test.png
const fileName = an.webpackStats[0].assets
.filter((asset) => asset.name.match(/^images/))[1].name;
request(an.app)
.get(`/${fileName}`)
.end((err, res) => {
if (err) done(err);
expect(res.status).toMatch(200);
an.shutdown(done);
});
})
.catch(done);
});
});

0 comments on commit 1cc4cfe

Please sign in to comment.