From bfeb26873ad41073a255656724b3ec05d7bcebf8 Mon Sep 17 00:00:00 2001 From: Elvin G Marmol Date: Thu, 7 Jan 2016 14:25:36 -0500 Subject: [PATCH 01/11] Set _urls on referenced content_type entries --- src/extension.js | 56 +++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 51 insertions(+), 5 deletions(-) diff --git a/src/extension.js b/src/extension.js index e4e66de..c16934b 100644 --- a/src/extension.js +++ b/src/extension.js @@ -64,6 +64,7 @@ export default class RootsContentful { let configuration = await configure_content(content_types) let content = await get_all_content(configuration) await set_urls(content) + await set_reference_urls(content) let entries = await transform_entries(content) let sorted = await sort_entries(entries) await this::set_locals(sorted) @@ -177,17 +178,62 @@ async function set_urls (types) { if (template) { return content.map(entry => { let paths = path(entry) - if (typeof paths === 'string') { - paths = [paths] - } - entry._urls = paths.map(path => `/${path}.html`) - entry._url = entry._urls.length === 1 ? entry._urls[0] : null + entry = set_entry_url(paths, entry) return entry._url }) } }) } +/** + * Checks content with single entry views for references to other content_types + * When present, sets `_url` and `_urls` properties on referenced entries + * `_url` takes the value `null` if the content type's custom path function + * returns multiple paths + * @param {Array} types - content type objects + * @return {Promise} - promise when urls are set + */ +async function set_reference_urls (types) { + let pathFns = {} + types = await Promise.all(types) + types.forEach((t) => { + if (t.path) { + pathFns[t.name] = { path: t.path } + } + }) + return types.map(({ template, content }) => { + if (template) { + let typeNames = Object.keys(pathFns) + return content.map(entry => { + return typeNames.forEach((name) => { + if (entry[name]) { + let paths = pathFns[name].path(entry.fields) + entry = set_entry_url(paths, entry.fields) + return entry + } + }) + }) + } + }) +} + +/** + * Sets `_url` and `_urls` properties on single entry views + * `_url` takes the value `null` if the content type's custom path function + * returns multiple paths + * @param {String} paths - String or Array of Strings of paths to assign + * @param {Object} entry - entry or entry.fields object to be assigned _urls + * @return {Object} - entry object + */ +function set_entry_url (paths, entry) { + if (typeof paths === 'string') { + paths = [paths] + } + entry._urls = paths.map(path => `/${path}.html`) + entry._url = entry._urls.length === 1 ? entry._urls[0] : null + return entry +} + /** * Builds locals object from types objects with content * @param {Array} types - populated content type objects From 53bbbc83e267df4a17bb4b1909cadf2f020a0318 Mon Sep 17 00:00:00 2001 From: Declan de Wet Date: Wed, 6 Jan 2016 18:51:29 +0200 Subject: [PATCH 02/11] lifecycle cleanup --- .travis.yml | 2 +- .../alt-content-type-config/app.coffee | 12 - .../alt-content-type-config/index.jade | 5 - .../alt-content-type-config/package.json | 6 - old_test/fixtures/basic/about.jade | 1 - old_test/fixtures/basic/app.coffee | 18 - old_test/fixtures/basic/index.jade | 5 - old_test/fixtures/basic/package.json | 6 - old_test/fixtures/custom_name/about.jade | 1 - old_test/fixtures/custom_name/app.coffee | 19 - old_test/fixtures/custom_name/index.jade | 5 - old_test/fixtures/custom_name/package.json | 6 - .../fixtures/image_view_helper/app.coffee | 18 - .../fixtures/image_view_helper/index.jade | 4 - .../fixtures/image_view_helper/package.json | 6 - old_test/fixtures/missing_config/app.coffee | 18 - old_test/fixtures/missing_config/index.jade | 5 - old_test/fixtures/missing_config/package.json | 6 - old_test/fixtures/missing_token/app.coffee | 16 - old_test/fixtures/missing_token/index.jade | 1 - old_test/fixtures/missing_token/package.json | 6 - old_test/fixtures/single_entry/app.coffee | 20 - old_test/fixtures/single_entry/index.jade | 4 - old_test/fixtures/single_entry/package.json | 6 - .../single_entry/views/_blog_post.jade | 3 - .../fixtures/single_entry_custom/app.coffee | 22 - .../fixtures/single_entry_custom/index.jade | 1 - .../fixtures/single_entry_custom/package.json | 7 - .../single_entry_custom/views/_blog_post.jade | 3 - .../fixtures/single_entry_multi/app.coffee | 22 - .../fixtures/single_entry_multi/index.jade | 7 - .../fixtures/single_entry_multi/package.json | 7 - .../single_entry_multi/views/_blog_post.jade | 4 - old_test/fixtures/sort/about.jade | 1 - old_test/fixtures/sort/app.coffee | 20 - old_test/fixtures/sort/index.jade | 5 - old_test/fixtures/sort/package.json | 6 - old_test/fixtures/sort/posts_expected.json | 1 - old_test/fixtures/transform/about.jade | 1 - old_test/fixtures/transform/app.coffee | 21 - old_test/fixtures/transform/index.jade | 5 - old_test/fixtures/transform/package.json | 6 - .../fixtures/transform/posts_expected.json | 1 - old_test/fixtures/write/about.jade | 1 - old_test/fixtures/write/app.coffee | 16 - old_test/fixtures/write/index.jade | 5 - old_test/fixtures/write/package.json | 6 - old_test/mocha.opts | 3 - old_test/test.js | 624 ------------------ package.json | 19 +- 50 files changed, 8 insertions(+), 1005 deletions(-) delete mode 100644 old_test/fixtures/alt-content-type-config/app.coffee delete mode 100644 old_test/fixtures/alt-content-type-config/index.jade delete mode 100644 old_test/fixtures/alt-content-type-config/package.json delete mode 100644 old_test/fixtures/basic/about.jade delete mode 100644 old_test/fixtures/basic/app.coffee delete mode 100644 old_test/fixtures/basic/index.jade delete mode 100644 old_test/fixtures/basic/package.json delete mode 100644 old_test/fixtures/custom_name/about.jade delete mode 100644 old_test/fixtures/custom_name/app.coffee delete mode 100644 old_test/fixtures/custom_name/index.jade delete mode 100644 old_test/fixtures/custom_name/package.json delete mode 100644 old_test/fixtures/image_view_helper/app.coffee delete mode 100644 old_test/fixtures/image_view_helper/index.jade delete mode 100644 old_test/fixtures/image_view_helper/package.json delete mode 100644 old_test/fixtures/missing_config/app.coffee delete mode 100644 old_test/fixtures/missing_config/index.jade delete mode 100644 old_test/fixtures/missing_config/package.json delete mode 100644 old_test/fixtures/missing_token/app.coffee delete mode 100644 old_test/fixtures/missing_token/index.jade delete mode 100644 old_test/fixtures/missing_token/package.json delete mode 100644 old_test/fixtures/single_entry/app.coffee delete mode 100644 old_test/fixtures/single_entry/index.jade delete mode 100644 old_test/fixtures/single_entry/package.json delete mode 100644 old_test/fixtures/single_entry/views/_blog_post.jade delete mode 100644 old_test/fixtures/single_entry_custom/app.coffee delete mode 100644 old_test/fixtures/single_entry_custom/index.jade delete mode 100644 old_test/fixtures/single_entry_custom/package.json delete mode 100644 old_test/fixtures/single_entry_custom/views/_blog_post.jade delete mode 100644 old_test/fixtures/single_entry_multi/app.coffee delete mode 100644 old_test/fixtures/single_entry_multi/index.jade delete mode 100644 old_test/fixtures/single_entry_multi/package.json delete mode 100644 old_test/fixtures/single_entry_multi/views/_blog_post.jade delete mode 100644 old_test/fixtures/sort/about.jade delete mode 100644 old_test/fixtures/sort/app.coffee delete mode 100644 old_test/fixtures/sort/index.jade delete mode 100644 old_test/fixtures/sort/package.json delete mode 100644 old_test/fixtures/sort/posts_expected.json delete mode 100644 old_test/fixtures/transform/about.jade delete mode 100644 old_test/fixtures/transform/app.coffee delete mode 100644 old_test/fixtures/transform/index.jade delete mode 100644 old_test/fixtures/transform/package.json delete mode 100644 old_test/fixtures/transform/posts_expected.json delete mode 100644 old_test/fixtures/write/about.jade delete mode 100644 old_test/fixtures/write/app.coffee delete mode 100644 old_test/fixtures/write/index.jade delete mode 100644 old_test/fixtures/write/package.json delete mode 100644 old_test/mocha.opts delete mode 100644 old_test/test.js diff --git a/.travis.yml b/.travis.yml index a2d8312..3a2448c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,5 +2,5 @@ language: node_js node_js: - "5" after_script: - - npm run coverage + - npm run coveralls sudo: false diff --git a/old_test/fixtures/alt-content-type-config/app.coffee b/old_test/fixtures/alt-content-type-config/app.coffee deleted file mode 100644 index c3d2b72..0000000 --- a/old_test/fixtures/alt-content-type-config/app.coffee +++ /dev/null @@ -1,12 +0,0 @@ -contentful = require '../../../src' - -module.exports = - ignores: ["**/_*", "**/.DS_Store"] - extensions: [ - contentful - access_token: 'YOUR_ACCESS_TOKEN' - space_id: 'aqzq2qya2jm4' - content_types: - blog_posts: - id: '6BYT1gNiIEyIw8Og8aQAO6' - ] diff --git a/old_test/fixtures/alt-content-type-config/index.jade b/old_test/fixtures/alt-content-type-config/index.jade deleted file mode 100644 index 4769500..0000000 --- a/old_test/fixtures/alt-content-type-config/index.jade +++ /dev/null @@ -1,5 +0,0 @@ -ul - - for p in contentful.blog_posts - li - h1= p.title - p= p.body diff --git a/old_test/fixtures/alt-content-type-config/package.json b/old_test/fixtures/alt-content-type-config/package.json deleted file mode 100644 index 2d0ae2c..0000000 --- a/old_test/fixtures/alt-content-type-config/package.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "name": "test", - "dependencies": { - "jade": "*" - } -} diff --git a/old_test/fixtures/basic/about.jade b/old_test/fixtures/basic/about.jade deleted file mode 100644 index 2763786..0000000 --- a/old_test/fixtures/basic/about.jade +++ /dev/null @@ -1 +0,0 @@ -h1 wow \ No newline at end of file diff --git a/old_test/fixtures/basic/app.coffee b/old_test/fixtures/basic/app.coffee deleted file mode 100644 index c2c261c..0000000 --- a/old_test/fixtures/basic/app.coffee +++ /dev/null @@ -1,18 +0,0 @@ -contentful = require '../../../src' - -module.exports = - ignores: ["**/_*", "**/.DS_Store"] - extensions: [ - contentful( - access_token: 'YOUR_ACCESS_TOKEN' - space_id: 'aqzq2qya2jm4' - content_types: [ - { - id: '6BYT1gNiIEyIw8Og8aQAO6' - } - { - id: '7CDlVsacqQc88cmIEGYWMa' - } - ] - ) - ] diff --git a/old_test/fixtures/basic/index.jade b/old_test/fixtures/basic/index.jade deleted file mode 100644 index 4769500..0000000 --- a/old_test/fixtures/basic/index.jade +++ /dev/null @@ -1,5 +0,0 @@ -ul - - for p in contentful.blog_posts - li - h1= p.title - p= p.body diff --git a/old_test/fixtures/basic/package.json b/old_test/fixtures/basic/package.json deleted file mode 100644 index 2d0ae2c..0000000 --- a/old_test/fixtures/basic/package.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "name": "test", - "dependencies": { - "jade": "*" - } -} diff --git a/old_test/fixtures/custom_name/about.jade b/old_test/fixtures/custom_name/about.jade deleted file mode 100644 index 8240f0e..0000000 --- a/old_test/fixtures/custom_name/about.jade +++ /dev/null @@ -1 +0,0 @@ -h1 wow diff --git a/old_test/fixtures/custom_name/app.coffee b/old_test/fixtures/custom_name/app.coffee deleted file mode 100644 index af220ac..0000000 --- a/old_test/fixtures/custom_name/app.coffee +++ /dev/null @@ -1,19 +0,0 @@ -contentful = require '../../../src' - -module.exports = - ignores: ["**/_*", "**/.DS_Store"] - extensions: [ - contentful( - access_token: 'YOUR_ACCESS_TOKEN' - space_id: 'aqzq2qya2jm4' - content_types: [ - { - id: '6BYT1gNiIEyIw8Og8aQAO6' - name: 'press_links' - }, - { - id: '7CDlVsacqQc88cmIEGYWMa' - } - ] - ) - ] diff --git a/old_test/fixtures/custom_name/index.jade b/old_test/fixtures/custom_name/index.jade deleted file mode 100644 index 190e01d..0000000 --- a/old_test/fixtures/custom_name/index.jade +++ /dev/null @@ -1,5 +0,0 @@ -ul - - for p in contentful.press_links - li - h1= p.title - p= p.body diff --git a/old_test/fixtures/custom_name/package.json b/old_test/fixtures/custom_name/package.json deleted file mode 100644 index 2d0ae2c..0000000 --- a/old_test/fixtures/custom_name/package.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "name": "test", - "dependencies": { - "jade": "*" - } -} diff --git a/old_test/fixtures/image_view_helper/app.coffee b/old_test/fixtures/image_view_helper/app.coffee deleted file mode 100644 index c2c261c..0000000 --- a/old_test/fixtures/image_view_helper/app.coffee +++ /dev/null @@ -1,18 +0,0 @@ -contentful = require '../../../src' - -module.exports = - ignores: ["**/_*", "**/.DS_Store"] - extensions: [ - contentful( - access_token: 'YOUR_ACCESS_TOKEN' - space_id: 'aqzq2qya2jm4' - content_types: [ - { - id: '6BYT1gNiIEyIw8Og8aQAO6' - } - { - id: '7CDlVsacqQc88cmIEGYWMa' - } - ] - ) - ] diff --git a/old_test/fixtures/image_view_helper/index.jade b/old_test/fixtures/image_view_helper/index.jade deleted file mode 100644 index 3eee69d..0000000 --- a/old_test/fixtures/image_view_helper/index.jade +++ /dev/null @@ -1,4 +0,0 @@ -ul - - for p in contentful.blog_posts - li - img(src!= asset(p.image, {w: 100, h: 100})) diff --git a/old_test/fixtures/image_view_helper/package.json b/old_test/fixtures/image_view_helper/package.json deleted file mode 100644 index 2d0ae2c..0000000 --- a/old_test/fixtures/image_view_helper/package.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "name": "test", - "dependencies": { - "jade": "*" - } -} diff --git a/old_test/fixtures/missing_config/app.coffee b/old_test/fixtures/missing_config/app.coffee deleted file mode 100644 index 2a318b6..0000000 --- a/old_test/fixtures/missing_config/app.coffee +++ /dev/null @@ -1,18 +0,0 @@ -contentful = require '../../../src' - -module.exports = - ignores: ["**/_*", "**/.DS_Store"] - extensions: [ - contentful( - access_token: 'YOUR_ACCESS_TOKEN' - space_id: 'aqzq2qya2jm4' - content_types: [ - { - name: 'test' - } - { - id: '7CDlVsacqQc88cmIEGYWMa' - } - ] - ) - ] diff --git a/old_test/fixtures/missing_config/index.jade b/old_test/fixtures/missing_config/index.jade deleted file mode 100644 index 4769500..0000000 --- a/old_test/fixtures/missing_config/index.jade +++ /dev/null @@ -1,5 +0,0 @@ -ul - - for p in contentful.blog_posts - li - h1= p.title - p= p.body diff --git a/old_test/fixtures/missing_config/package.json b/old_test/fixtures/missing_config/package.json deleted file mode 100644 index 2d0ae2c..0000000 --- a/old_test/fixtures/missing_config/package.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "name": "test", - "dependencies": { - "jade": "*" - } -} diff --git a/old_test/fixtures/missing_token/app.coffee b/old_test/fixtures/missing_token/app.coffee deleted file mode 100644 index 6b8b34a..0000000 --- a/old_test/fixtures/missing_token/app.coffee +++ /dev/null @@ -1,16 +0,0 @@ -contentful = require '../../../src' - -module.exports = - ignores: ["**/_*", "**/.DS_Store"] - extensions: [ - contentful( - content_types: [ - { - name: 'test' - } - { - id: '7CDlVsacqQc88cmIEGYWMa' - } - ] - ) - ] diff --git a/old_test/fixtures/missing_token/index.jade b/old_test/fixtures/missing_token/index.jade deleted file mode 100644 index 8240f0e..0000000 --- a/old_test/fixtures/missing_token/index.jade +++ /dev/null @@ -1 +0,0 @@ -h1 wow diff --git a/old_test/fixtures/missing_token/package.json b/old_test/fixtures/missing_token/package.json deleted file mode 100644 index 2d0ae2c..0000000 --- a/old_test/fixtures/missing_token/package.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "name": "test", - "dependencies": { - "jade": "*" - } -} diff --git a/old_test/fixtures/single_entry/app.coffee b/old_test/fixtures/single_entry/app.coffee deleted file mode 100644 index b9d39a8..0000000 --- a/old_test/fixtures/single_entry/app.coffee +++ /dev/null @@ -1,20 +0,0 @@ -contentful = require '../../../src' - -module.exports = - ignores: ["**/_*", "**/.DS_Store"] - extensions: [ - contentful( - access_token: 'YOUR_ACCESS_TOKEN' - space_id: 'aqzq2qya2jm4' - content_types: [ - { - id: '6BYT1gNiIEyIw8Og8aQAO6' - name: 'blog_posts' - template: 'views/_blog_post.jade' - } - ] - ) - ] - - locals: - wow: 'such local' diff --git a/old_test/fixtures/single_entry/index.jade b/old_test/fixtures/single_entry/index.jade deleted file mode 100644 index b881d53..0000000 --- a/old_test/fixtures/single_entry/index.jade +++ /dev/null @@ -1,4 +0,0 @@ -- for p in contentful.blog_posts - h1= p.title - p= p.body - a(href= p._url) Link diff --git a/old_test/fixtures/single_entry/package.json b/old_test/fixtures/single_entry/package.json deleted file mode 100644 index 2d0ae2c..0000000 --- a/old_test/fixtures/single_entry/package.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "name": "test", - "dependencies": { - "jade": "*" - } -} diff --git a/old_test/fixtures/single_entry/views/_blog_post.jade b/old_test/fixtures/single_entry/views/_blog_post.jade deleted file mode 100644 index 78a5b6c..0000000 --- a/old_test/fixtures/single_entry/views/_blog_post.jade +++ /dev/null @@ -1,3 +0,0 @@ -h1= entry.title -p= entry.body -p= wow diff --git a/old_test/fixtures/single_entry_custom/app.coffee b/old_test/fixtures/single_entry_custom/app.coffee deleted file mode 100644 index a73a4bc..0000000 --- a/old_test/fixtures/single_entry_custom/app.coffee +++ /dev/null @@ -1,22 +0,0 @@ -slugify = require 'underscore.string/slugify' -contentful = require '../../../src' - -module.exports = - ignores: ["**/_*", "**/.DS_Store"] - extensions: [ - contentful( - access_token: 'YOUR_ACCESS_TOKEN' - space_id: 'aqzq2qya2jm4' - content_types: [ - { - id: '6BYT1gNiIEyIw8Og8aQAO6' - name: 'blog_posts' - template: 'views/_blog_post.jade' - path: (e) -> "blogging/#{e.category}/#{slugify(e.title)}" - } - ] - ) - ] - - locals: - wow: 'such local' diff --git a/old_test/fixtures/single_entry_custom/index.jade b/old_test/fixtures/single_entry_custom/index.jade deleted file mode 100644 index 8240f0e..0000000 --- a/old_test/fixtures/single_entry_custom/index.jade +++ /dev/null @@ -1 +0,0 @@ -h1 wow diff --git a/old_test/fixtures/single_entry_custom/package.json b/old_test/fixtures/single_entry_custom/package.json deleted file mode 100644 index 1a248fc..0000000 --- a/old_test/fixtures/single_entry_custom/package.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "name": "test", - "dependencies": { - "jade": "*", - "underscore.string": "*" - } -} diff --git a/old_test/fixtures/single_entry_custom/views/_blog_post.jade b/old_test/fixtures/single_entry_custom/views/_blog_post.jade deleted file mode 100644 index 78a5b6c..0000000 --- a/old_test/fixtures/single_entry_custom/views/_blog_post.jade +++ /dev/null @@ -1,3 +0,0 @@ -h1= entry.title -p= entry.body -p= wow diff --git a/old_test/fixtures/single_entry_multi/app.coffee b/old_test/fixtures/single_entry_multi/app.coffee deleted file mode 100644 index 503e364..0000000 --- a/old_test/fixtures/single_entry_multi/app.coffee +++ /dev/null @@ -1,22 +0,0 @@ -slugify = require 'underscore.string/slugify' -contentful = require '../../../src' - -module.exports = - ignores: ["**/_*", "**/.DS_Store"] - extensions: [ - contentful( - access_token: 'YOUR_ACCESS_TOKEN' - space_id: 'aqzq2qya2jm4' - content_types: [ - { - id: '6BYT1gNiIEyIw8Og8aQAO6' - name: 'blog_posts' - template: 'views/_blog_post.jade' - path: (e) -> ("#{lang}/#{slugify(e.title)}" for lang in ['en', 'fr']) - } - ] - ) - ] - - locals: - wow: 'such local' diff --git a/old_test/fixtures/single_entry_multi/index.jade b/old_test/fixtures/single_entry_multi/index.jade deleted file mode 100644 index ee98265..0000000 --- a/old_test/fixtures/single_entry_multi/index.jade +++ /dev/null @@ -1,7 +0,0 @@ -- for p in contentful.blog_posts - h1= p.title - p= p.body - ul - each url in p._urls - li - a(href=url)= url diff --git a/old_test/fixtures/single_entry_multi/package.json b/old_test/fixtures/single_entry_multi/package.json deleted file mode 100644 index 1a248fc..0000000 --- a/old_test/fixtures/single_entry_multi/package.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "name": "test", - "dependencies": { - "jade": "*", - "underscore.string": "*" - } -} diff --git a/old_test/fixtures/single_entry_multi/views/_blog_post.jade b/old_test/fixtures/single_entry_multi/views/_blog_post.jade deleted file mode 100644 index 4355d6d..0000000 --- a/old_test/fixtures/single_entry_multi/views/_blog_post.jade +++ /dev/null @@ -1,4 +0,0 @@ -h1= entry.title -p= entry.body -p= entry._url -p= wow diff --git a/old_test/fixtures/sort/about.jade b/old_test/fixtures/sort/about.jade deleted file mode 100644 index 8240f0e..0000000 --- a/old_test/fixtures/sort/about.jade +++ /dev/null @@ -1 +0,0 @@ -h1 wow diff --git a/old_test/fixtures/sort/app.coffee b/old_test/fixtures/sort/app.coffee deleted file mode 100644 index 22f1105..0000000 --- a/old_test/fixtures/sort/app.coffee +++ /dev/null @@ -1,20 +0,0 @@ -contentful = require '../../../src' - -megaSort = (a, b)-> - a.title.localeCompare(b.title) - -module.exports = - ignores: ["**/_*", "**/.DS_Store"] - extensions: [ - contentful( - access_token: 'YOUR_ACCESS_TOKEN' - space_id: 'aqzq2qya2jm4' - content_types: [ - { - id: '6BYT1gNiIEyIw8Og8aQAO6', - write: 'posts.json', - sort: megaSort - } - ] - ) - ] diff --git a/old_test/fixtures/sort/index.jade b/old_test/fixtures/sort/index.jade deleted file mode 100644 index 4769500..0000000 --- a/old_test/fixtures/sort/index.jade +++ /dev/null @@ -1,5 +0,0 @@ -ul - - for p in contentful.blog_posts - li - h1= p.title - p= p.body diff --git a/old_test/fixtures/sort/package.json b/old_test/fixtures/sort/package.json deleted file mode 100644 index 2d0ae2c..0000000 --- a/old_test/fixtures/sort/package.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "name": "test", - "dependencies": { - "jade": "*" - } -} diff --git a/old_test/fixtures/sort/posts_expected.json b/old_test/fixtures/sort/posts_expected.json deleted file mode 100644 index 2801a26..0000000 --- a/old_test/fixtures/sort/posts_expected.json +++ /dev/null @@ -1 +0,0 @@ -[{"title":"Title A","body":"Nothing interesting"},{"title":"Title B","body":"Something else"},{"title":"Title C","body":"Rich Boy selling crick"}] \ No newline at end of file diff --git a/old_test/fixtures/transform/about.jade b/old_test/fixtures/transform/about.jade deleted file mode 100644 index 8240f0e..0000000 --- a/old_test/fixtures/transform/about.jade +++ /dev/null @@ -1 +0,0 @@ -h1 wow diff --git a/old_test/fixtures/transform/app.coffee b/old_test/fixtures/transform/app.coffee deleted file mode 100644 index 68f04ec..0000000 --- a/old_test/fixtures/transform/app.coffee +++ /dev/null @@ -1,21 +0,0 @@ -contentful = require '../../../src' - -megaTransform = (entry)-> - delete entry.body - entry - -module.exports = - ignores: ["**/_*", "**/.DS_Store"] - extensions: [ - contentful( - access_token: 'YOUR_ACCESS_TOKEN' - space_id: 'aqzq2qya2jm4' - content_types: [ - { - id: '6BYT1gNiIEyIw8Og8aQAO6', - write: 'posts.json', - transform: megaTransform - } - ] - ) - ] diff --git a/old_test/fixtures/transform/index.jade b/old_test/fixtures/transform/index.jade deleted file mode 100644 index 4769500..0000000 --- a/old_test/fixtures/transform/index.jade +++ /dev/null @@ -1,5 +0,0 @@ -ul - - for p in contentful.blog_posts - li - h1= p.title - p= p.body diff --git a/old_test/fixtures/transform/package.json b/old_test/fixtures/transform/package.json deleted file mode 100644 index 2d0ae2c..0000000 --- a/old_test/fixtures/transform/package.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "name": "test", - "dependencies": { - "jade": "*" - } -} diff --git a/old_test/fixtures/transform/posts_expected.json b/old_test/fixtures/transform/posts_expected.json deleted file mode 100644 index 719b928..0000000 --- a/old_test/fixtures/transform/posts_expected.json +++ /dev/null @@ -1 +0,0 @@ -[{"title":"Title C"},{"title":"Title B"},{"title":"Title A"}] \ No newline at end of file diff --git a/old_test/fixtures/write/about.jade b/old_test/fixtures/write/about.jade deleted file mode 100644 index 8240f0e..0000000 --- a/old_test/fixtures/write/about.jade +++ /dev/null @@ -1 +0,0 @@ -h1 wow diff --git a/old_test/fixtures/write/app.coffee b/old_test/fixtures/write/app.coffee deleted file mode 100644 index 4bd0770..0000000 --- a/old_test/fixtures/write/app.coffee +++ /dev/null @@ -1,16 +0,0 @@ -contentful = require '../../../src' - -module.exports = - ignores: ["**/_*", "**/.DS_Store"] - extensions: [ - contentful( - access_token: 'YOUR_ACCESS_TOKEN' - space_id: 'aqzq2qya2jm4' - content_types: [ - { - id: '6BYT1gNiIEyIw8Og8aQAO6', - write: 'posts.json' - } - ] - ) - ] diff --git a/old_test/fixtures/write/index.jade b/old_test/fixtures/write/index.jade deleted file mode 100644 index 4769500..0000000 --- a/old_test/fixtures/write/index.jade +++ /dev/null @@ -1,5 +0,0 @@ -ul - - for p in contentful.blog_posts - li - h1= p.title - p= p.body diff --git a/old_test/fixtures/write/package.json b/old_test/fixtures/write/package.json deleted file mode 100644 index 2d0ae2c..0000000 --- a/old_test/fixtures/write/package.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "name": "test", - "dependencies": { - "jade": "*" - } -} diff --git a/old_test/mocha.opts b/old_test/mocha.opts deleted file mode 100644 index 9ee4f1d..0000000 --- a/old_test/mocha.opts +++ /dev/null @@ -1,3 +0,0 @@ ---reporter spec ---compilers js:babel-register,coffee:coffee-script/register ---timeout 90000 diff --git a/old_test/test.js b/old_test/test.js deleted file mode 100644 index 66ebbf9..0000000 --- a/old_test/test.js +++ /dev/null @@ -1,624 +0,0 @@ -/* - NOTE: these tests have been (mostly) compiled by coffee-script. - We require minimal ES6 syntax so we can take advantage - of the way modules are structured in `lib/`. - These tests are temporary and will eventually be translated - to the AVA test runner pending an update to support Babel 6.0. - */ - -import 'babel-polyfill' -import chai from 'chai' -import chai_promise from 'chai-as-promised' -import mockery from 'mockery' -import path from 'path' -import RootsUtil from 'roots-util' -import Roots from 'roots' -import slugify from 'underscore.string/slugify' -import W from 'when' -import _ from 'lodash' - -let _path = path.join(__dirname, './fixtures') -let h = new RootsUtil.Helpers({ base: _path }) - -chai.should() -chai.use(chai_promise) - -function compile_fixture (fixture_name, done) { - this['public'] = path.join(fixture_name, 'public') - return h.project.compile(Roots, fixture_name) -} - -function mock_contentful (opts) { - if (opts == null) { - opts = {} - } - mockery.enable({ - warnOnUnregistered: false, - useCleanCache: true - }) - opts = _.defaults(opts, { - entries: [ - { - sys: { - sys: 'data' - }, - fields: { - title: 'Default Title', - body: 'Default Body' - } - } - ], - content_type: { - name: 'Blog Post', - displayField: 'title' - } - }) - return mockery.registerMock('contentful', { - createClient: function () { - return { - contentType: function () { - return W.resolve(opts.content_type) - }, - entries: function () { - return W.resolve(opts.entries) - } - } - } - }) -} - -function unmock_contentful () { - mockery.deregisterAll() - return mockery.disable() -} - -before(function (done) { - return h.project.install_dependencies('*', done) -}) - -after(function () { - return h.project.remove_folders('**/public') -}) - -describe('config', function () { - before(function () { - this.title = 'Gatorade' - this.body = 'Yung Lean' - return mock_contentful({ - entries: [ - { - fields: { - title: this.title, - body: this.body - } - } - ] - }) - }) - it('should throw an error when missing an access token', function () { - return function () { - return compile_fixture.call(this, 'missing_token') - }.should['throw']() - }) - it('should throw an error without content type id', function () { - return compile_fixture.call(this, 'missing_config').should.be.rejected - }) - it('allows the content type name to be set through a k/v object config', function (done) { - return compile_fixture.call(this, 'alt-content-type-config')['with'](this).then(function () { - var p - p = path.join(this['public'], 'index.html') - h.file.contains(p, this.title).should.be['true'] - return h.file.contains(p, this.body).should.be['true'] - }).then(function () { - return done() - })['catch'](done) - }) - return after(function () { - return unmock_contentful() - }) -}) - -describe('contentful content type fields', function () { - before(function () { - return mock_contentful({ - entries: [ - { - fields: { - sys: 'test' - } - } - ] - }) - }) - it('should throw an error if `sys` is a field name', function () { - return compile_fixture.call(this, 'basic').should.be.rejected - }) - return after(function () { - return unmock_contentful() - }) -}) - -describe('basic compile', function () { - var project = new Roots(path.join(_path, 'basic')) - var util = new RootsUtil(project) - before(function (done) { - this.title = 'Throw Some Ds' - this.body = 'Rich Boy selling crick' - mock_contentful({ - entries: [ - { - fields: { - title: this.title, - body: this.body - } - } - ] - }) - util.write('../about.jade', 'h1 wow') - return compile_fixture.call(this, 'basic').then(function () { - return done() - })['catch'](done) - }) - it('compiles basic project', function () { - var p - p = path.join(this['public'], 'index.html') - return h.file.exists(p).should.be.ok - }) - it('has contentful data available in views', function () { - var p - p = path.join(this['public'], 'index.html') - h.file.contains(p, this.title).should.be['true'] - return h.file.contains(p, this.body).should.be['true'] - }) - it('compiles multiple times including watch', async function () { - var index = path.join(this['public'], 'index.html') - var about = path.join(this['public'], 'about.html') - - console.log('starting watcher') - var watcher = await project.watch() - - console.log('compile 1') - h.file.contains(index, this.title).should.be['true'] - h.file.contains(index, this.body).should.be['true'] - - console.log('modifying fixture') - await util.write('../about.jade', 'h1 Chuck some Ds\nh2 Wealthy lad peddling crick') - - console.log('verifying changes') - h.file.contains(about, 'Chuck some Ds').should.be['true'] - h.file.contains(about, 'Wealthy lad peddling crick').should.be['true'] - - console.log('closing watcher') - watcher.close() - console.log('watcher closed') - - // var watcher = null - // var second_compile = false - // project.on('done', async function () { - // var p = path.join(this['public'], 'index.html') - // if (!second_compile) { - // console.log('compile 1') - // h.file.contains(p, this.title).should.be['true'] - // h.file.contains(p, this.body).should.be['true'] - // second_compile = true - // } else { - // console.log('compile 2') - // h.file.contains(p, 'Chuck some Ds').should.be['true'] - // h.file.contains(p, 'Wealthy lad peddling crick').should.be['true'] - // console.log(watcher) - // if (watcher != null) { - // await watcher.close() - // console.log('watcher closed') - // } - // } - // }.bind(this)) - // watcher = await project.watch() - // console.log('watcher opened') - // console.log(watcher) - // await util.write('../about.jade', 'h1 Chuck some Ds\nh2 Wealthy lad peddling crick') - }) - return after(function () { - util.write('../about.jade', 'h1 wow') - return unmock_contentful() - }) -}) - -describe('write as json', function () { - before(function (done) { - this.title = 'Throw Some Ds' - this.body = 'Rich Boy selling crick' - mock_contentful({ - entries: [ - { - fields: { - title: this.title, - body: this.body - } - } - ] - }) - return compile_fixture.call(this, 'write').then(function () { - return done() - })['catch'](done) - }) - it('compiles project', function () { - var p - p = path.join(this['public'], 'index.html') - return h.file.exists(p).should.be.ok - }) - it('has written data as json', function () { - var p - p = path.join(this['public'], 'posts.json') - h.file.exists(p).should.be.ok - h.file.contains(p, this.title).should.be['true'] - return h.file.contains(p, this.body).should.be['true'] - }) - return after(function () { - return unmock_contentful() - }) -}) - -describe('data manipulation', function () { - describe('sort', function () { - before(function (done) { - var index - this.titles = ['Title C', 'Title B', 'Title A'] - this.bodies = ['Rich Boy selling crick', 'Something else', 'Nothing interesting'] - this.entries = function () { - var j, results - results = [] - for (index = j = 0; j <= 2; index = ++j) { - results.push({ - fields: { - title: this.titles[index], - body: this.bodies[index] - } - }) - } - return results - }.call(this) - mock_contentful({ - entries: this.entries - }) - return compile_fixture.call(this, 'sort').then(function () { - return done() - })['catch'](done) - }) - it('compiles project', function () { - var p - p = path.join(this['public'], 'index.html') - return h.file.exists(p).should.be.ok - }) - it('orders data correctly for the project', function () { - var body, j, len, p, ref, results - p = path.join(this['public'], 'index.html') - h.file.contains_match(p, '^.*(Title A)[/<>\\w\\s]*(Title B)[/<>\\w\\s]*(Title C).*$').should.be['true'] - ref = this.bodies - results = [] - for (j = 0, len = ref.length; j < len; j++) { - body = ref[j] - results.push(h.file.contains(p, body).should.be['true']) - } - return results - }) - it('has written data as json', function () { - var p - p = path.join(this['public'], 'posts.json') - h.file.exists(p).should.be.ok - return h.file.matches_file(p, 'sort/posts_expected.json').should.be['true'] - }) - return after(function () { - return unmock_contentful() - }) - }) - return describe('transform', function () { - before(function (done) { - var index - this.titles = ['Title C', 'Title B', 'Title A'] - this.bodies = ['Rich Boy selling crick', 'Something else', 'Nothing interesting'] - this.entries = function () { - var j, results - results = [] - for (index = j = 0; j <= 2; index = ++j) { - results.push({ - fields: { - title: this.titles[index], - body: this.bodies[index] - } - }) - } - return results - }.call(this) - mock_contentful({ - entries: this.entries - }) - return compile_fixture.call(this, 'transform').then(function () { - return done() - })['catch'](done) - }) - it('compiles project', function () { - var p - p = path.join(this['public'], 'index.html') - return h.file.exists(p).should.be.ok - }) - it('does not reorder data', function () { - var p - p = path.join(this['public'], 'index.html') - return h.file.contains_match(p, '^.*(Title C)[/<>\\w\\s]*(Title B)[/<>\\w\\s]*(Title A).*$').should.be['true'] - }) - it('has manipulated data correctly for the project', function () { - var body, j, len, p, ref, results - p = path.join(this['public'], 'index.html') - ref = this.bodies - results = [] - for (j = 0, len = ref.length; j < len; j++) { - body = ref[j] - results.push(h.file.contains(p, body).should.be['false']) - } - return results - }) - it('has written data as json', function () { - var p - p = path.join(this['public'], 'posts.json') - h.file.exists(p).should.be.ok - return h.file.matches_file(p, 'transform/posts_expected.json').should.be['true'] - }) - return after(function () { - return unmock_contentful() - }) - }) -}) - -describe('custom name for view helper local', function () { - before(function (done) { - this.title = 'Throw Some Ds' - this.body = 'Rich Boy selling crack' - mock_contentful({ - entries: [ - { - fields: { - title: this.title, - body: this.body - } - } - ] - }) - return compile_fixture.call(this, 'custom_name').then(function () { - return done() - })['catch'](done) - }) - it('has contentful data available in views under a custom name', function () { - var p - p = path.join(this['public'], 'index.html') - h.file.contains(p, this.title).should.be['true'] - return h.file.contains(p, this.body).should.be['true'] - }) - return after(function () { - return unmock_contentful() - }) -}) - -describe('single entry views', function () { - describe('default path function', function () { - before(function (done) { - this.title = 'Real Talk' - this.body = "I'm not about to sit up here, and argue about who's to blame." - mock_contentful({ - entries: [ - { - fields: { - title: this.title, - body: this.body - } - } - ], - content_type: { - name: 'Blog Post', - displayField: 'title' - } - }) - return compile_fixture.call(this, 'single_entry').then(function () { - return done() - })['catch'](done) - }) - it('compiles a single entry file based off the slugified display field', function () { - var p - p = path.join(this['public'], 'blog_posts/' + slugify(this.title) + '.html') - h.file.exists(p).should.be.ok - h.file.contains(p, this.title).should.be['true'] - return h.file.contains(p, this.body).should.be['true'] - }) - it('has access to other roots locals inside the single entry view', function () { - var p - p = path.join(this['public'], 'blog_posts/' + slugify(this.title) + '.html') - return h.file.contains(p, 'such local').should.be['true'] - }) - it('sets a _url attribute to allow links to each entry', function () { - var p - p = path.join(this['public'], 'index.html') - return h.file.contains(p, '/blog_posts/real-talk.html').should.be['true'] - }) - return after(function () { - return unmock_contentful() - }) - }) - describe('should clear entry locals between each single view compile', function () { - before(function (done) { - this.title = 'Wow such doge' - this.body = 'such amaze' - this.title_2 = 'Totes McGotes' - this.body_2 = null - mock_contentful({ - entries: [ - { - fields: { - title: this.title, - body: this.body - } - }, { - fields: { - title: this.title_2 - } - } - ], - content_type: { - name: 'Blog Post', - displayField: 'title' - } - }) - return compile_fixture.call(this, 'single_entry').then(function () { - return done() - })['catch'](done) - }) - after(function () { - return unmock_contentful() - }) - return it("should not have first entry's content in second entries single view", function () { - var p - p = path.join(this['public'], 'blog_posts/' + slugify(this.title_2) + '.html') - return h.file.contains(p, this.body).should.not.be['true'] - }) - }) - describe('custom path function', function () { - before(function (done) { - this.title = 'Real Talk' - this.body = "I'm not about to sit up here, and argue about who's to blame." - this.category = 'greatest_hits' - mock_contentful({ - entries: [ - { - fields: { - title: this.title, - body: this.body, - category: this.category - } - } - ], - content_type: { - name: 'Blog Post', - displayField: 'title' - } - }) - return compile_fixture.call(this, 'single_entry_custom').then(function () { - return done() - })['catch'](done) - }) - it('compiles a single entry file using custom path', function () { - var output, p - output = 'blogging/' + this.category + '/' + slugify(this.title) + '.html' - p = path.join(this['public'], output) - h.file.exists(p).should.be.ok - h.file.contains(p, this.title).should.be['true'] - return h.file.contains(p, this.body).should.be['true'] - }) - return after(function () { - return unmock_contentful() - }) - }) - describe('custom multi-path function', function () { - before(function (done) { - this.title = ['Real Talk', 'Fake Talk'] - this.body = ["I'm not about to sit up here, and argue about who's to blame.", "I'm about to sit up here, and not argue about who's not to blame."] - mock_contentful({ - entries: [ - { - fields: { - title: this.title[0], - body: this.body[0] - } - }, { - fields: { - title: this.title[1], - body: this.body[1] - } - } - ], - content_type: { - name: 'Blog Post', - displayField: 'title' - } - }) - return compile_fixture.call(this, 'single_entry_multi').then(function () { - return done() - })['catch'](done) - }) - it('compiles a single entry to multiple files', function () { - var i, j, lang, len, output, p, ref, results - ref = ['en', 'fr'] - results = [] - for (j = 0, len = ref.length; j < len; j++) { - lang = ref[j] - results.push(function () { - var k, len1, ref1, results1 - ref1 = [0, 1] - results1 = [] - for (k = 0, len1 = ref1.length; k < len1; k++) { - i = ref1[k] - output = '/' + lang + '/' + slugify(this.title[i]) + '.html' - p = path.join(this['public'], output) - h.file.exists(p).should.be.ok - h.file.contains(p, this.title[i]).should.be['true'] - h.file.contains(p, this.body[i]).should.be['true'] - results1.push(h.file.contains(p, '

' + output + '

').should.be['true']) - } - return results1 - }.call(this)) - } - return results - }) - it("sets _urls attribute to all of the entry's compiled files", function () { - var i, j, lang, len, p, ref, results - p = path.join(this['public'], 'index.html') - ref = ['en', 'fr'] - results = [] - for (j = 0, len = ref.length; j < len; j++) { - lang = ref[j] - results.push(function () { - var k, len1, ref1, results1 - ref1 = [0, 1] - results1 = [] - for (k = 0, len1 = ref1.length; k < len1; k++) { - i = ref1[k] - results1.push(h.file.contains(p, '/' + lang + '/' + slugify(this.title[i]) + '.html').should.be['true']) - } - return results1 - }.call(this)) - } - return results - }) - return after(function () { - return unmock_contentful() - }) - }) - return describe('image view helper function', function () { - before(function (done) { - this.img_path = 'http://dogesay.com/wow.jpg' - mock_contentful({ - entries: [ - { - fields: { - image: { - fields: { - file: { - url: this.img_path - } - } - } - } - } - ] - }) - return compile_fixture.call(this, 'image_view_helper').then(function () { - return done() - })['catch'](done) - }) - it('adds query string params to the image', function () { - var p - p = path.join(this['public'], 'index.html') - return h.file.contains(p, this.img_path + '?w=100&h=100').should.be['true'] - }) - return after(function () { - return unmock_contentful() - }) - }) -}) diff --git a/package.json b/package.json index ad350f7..5fe76ac 100644 --- a/package.json +++ b/package.json @@ -61,27 +61,22 @@ }, "scripts": { "build": "babel src -d lib", - "precoverage": "nyc npm test", - "coverage": "nyc report --reporter=text-lcov | coveralls", + "coverage": "nyc report --reporter=lcov", + "coveralls": "coveralls < coverage/lcov.info", + "debug-test": "npm run test -- --serial --verbose --fail-fast", "lint": "standard --verbose | snazzy", "postpublish": "git push --follow-tags", + "posttest": "babel-node ./test/_teardown.js", "prebuild": "npm test", "precommit": "npm run lint -s", + "precoverage": "nyc npm test", "precoveralls": "npm run coverage", "prerelease": "npm run build", - "pretest": "npm run lint -s", + "pretest": "npm run lint -s && babel-node ./test/_setup.js", "release": "npm publish", "test": "nyc ava --require babel-core/register --require coffee-script/register" }, "standard": { - "parser": "babel-eslint", - "globals": [ - "describe", - "it", - "before", - "after", - "beforeAll", - "afterAll" - ] + "parser": "babel-eslint" } } From 56f07b79d9dc68c18d07a1af2cf197125eabe746 Mon Sep 17 00:00:00 2001 From: Declan de Wet Date: Wed, 6 Jan 2016 18:58:58 +0200 Subject: [PATCH 03/11] update make tasks --- Makefile | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Makefile b/Makefile index a6586d7..844d2c5 100644 --- a/Makefile +++ b/Makefile @@ -12,3 +12,9 @@ release: lint: npm run lint + +debug-test: + npm run debug-test + +test:: + npm test From a62df1b81f7dee6084b0bc3fa556b969ec4addb3 Mon Sep 17 00:00:00 2001 From: Declan de Wet Date: Wed, 6 Jan 2016 19:39:24 +0200 Subject: [PATCH 04/11] document lifecycle changes, add request debugging to debug-test task --- contributing.md | 36 +++++++++++++++++++++--------------- package.json | 2 +- 2 files changed, 22 insertions(+), 16 deletions(-) diff --git a/contributing.md b/contributing.md index 0486c33..faa686f 100644 --- a/contributing.md +++ b/contributing.md @@ -1,5 +1,5 @@ -# Contributing to Roots-contentful +# Contributing to `roots-contentful` Hello there! First of all, thanks for being interested in this project and helping out. We all think you are awesome, and by contributing to open source projects, you are making the world a better place. That being said, there are a few ways to make the process of contributing code to this project smoother, detailed below: @@ -14,9 +14,9 @@ If you are opening an issue about a bug, make sure that you include clear steps - Run `npm install` - Put in work -### `pre-push`, `pre-commit` Linting +### `pre-commit` Linting -Provided dependencies are installed, `git push` and `git commit` will +Provided dependencies are installed, `git commit` will not work unless this project passes a linting check. ### Build Commands @@ -26,32 +26,35 @@ not work unless this project passes a linting check. #### Testing -This project is constantly evolving, and to ensure that things are secure and working for everyone, we need to have tests. If you are adding a new feature, please make sure to add a test for it. The test suite for this project uses [mocha](http://visionmedia.github.io/mocha/) and [chai](http://chaijs.com/) +This project is constantly evolving, and to ensure that things are secure and working for everyone, we need to have tests. If you are adding a new feature, please make sure to add a test for it. The test suite for this project uses [AVA](https://github.com/sindresorhus/ava). To lint the source: -``` +```shell $ make lint ``` To lint the source and run the tests: -```bash -$ npm test -# or, for optional request logging: -$ NODE_DEBUG=request npm test +```shell +$ make test ``` +By default, tests will run concurrently/in parallel. When debugging, this can sometimes lead to unwanted behavior. For this reason, there is a `debug-test` command that will fail as soon as the first test fails, run tests serially, enable more verbose output and also log any HTTP requests: + +```shell +$ make debug-test +``` To create a coverage report: -``` +```shell $ make coverage ``` To feed a coverage report to coveralls: -``` +```shell $ make coveralls ``` @@ -62,7 +65,7 @@ $ make coveralls Building involves compiling the ES2016 syntax down to regular ES5 using [Babel](http://babeljs.io). This command will run the tests - on success it will then compile the contents of `src/` into `lib/`. -``` +```shell $ make build ``` @@ -70,16 +73,19 @@ $ make build This command will lint the project files, run the tests, build the project, publish the build to NPM and then perform a `git push --follow-tags`. -``` +```shell $ make release ``` A typical publish workflow might look something like this: -``` -$ git checkout master +```shell +$ git checkout Fix/bug-fix +# add some code... $ git add . $ git commit -m "fixed a bug" +$ git checkout master +$ git merge Fix/bug-fix $ npm version patch $ make release ``` diff --git a/package.json b/package.json index 5fe76ac..a67f178 100644 --- a/package.json +++ b/package.json @@ -63,7 +63,7 @@ "build": "babel src -d lib", "coverage": "nyc report --reporter=lcov", "coveralls": "coveralls < coverage/lcov.info", - "debug-test": "npm run test -- --serial --verbose --fail-fast", + "debug-test": "NODE_DEBUG=request npm run test -- --serial --verbose --fail-fast", "lint": "standard --verbose | snazzy", "postpublish": "git push --follow-tags", "posttest": "babel-node ./test/_teardown.js", From 7f81fdf2f84ee66d56e1325a97d939facce8ea3a Mon Sep 17 00:00:00 2001 From: Declan de Wet Date: Wed, 6 Jan 2016 20:39:46 +0200 Subject: [PATCH 05/11] begin test performance improvements --- .gitignore | 1 + package.json | 7 ++- test/_helpers.js | 62 ++++++++++++++++++- test/_setup.js | 62 +++---------------- test/_teardown.js | 14 +++++ test/basic-compile.js | 11 +--- test/config.js | 11 +--- test/contentful-content-type-fields.js | 10 +-- test/custom-name-for-view-helper-local.js | 11 +--- test/data-manipulation-sort.js | 11 +--- test/data-manipulation-transform.js | 11 +--- ...clear-entry-locals-between-each-compile.js | 11 +--- ...-entry-views-custom-multi-path-function.js | 11 +--- ...single-entry-views-custom-path-function.js | 11 +--- ...ingle-entry-views-default-path-function.js | 11 +--- ...-entry-views-image-view-helper-function.js | 11 +--- test/write-as-json.js | 11 +--- 17 files changed, 121 insertions(+), 156 deletions(-) create mode 100644 test/_teardown.js diff --git a/.gitignore b/.gitignore index d1412c4..885f017 100644 --- a/.gitignore +++ b/.gitignore @@ -13,3 +13,4 @@ lib-cov .lock-wscript build/Release .nyc_output +test/fixtures/*/public diff --git a/package.json b/package.json index a67f178..80aba09 100644 --- a/package.json +++ b/package.json @@ -66,17 +66,18 @@ "debug-test": "NODE_DEBUG=request npm run test -- --serial --verbose --fail-fast", "lint": "standard --verbose | snazzy", "postpublish": "git push --follow-tags", - "posttest": "babel-node ./test/_teardown.js", + "posttest": "node test/_teardown.js", "prebuild": "npm test", "precommit": "npm run lint -s", "precoverage": "nyc npm test", "precoveralls": "npm run coverage", "prerelease": "npm run build", - "pretest": "npm run lint -s && babel-node ./test/_setup.js", + "pretest": "npm run lint -s && node test/_setup.js", "release": "npm publish", "test": "nyc ava --require babel-core/register --require coffee-script/register" }, "standard": { - "parser": "babel-eslint" + "parser": "babel-eslint", + "ignore": ["test/_setup.js", "test/_teardown.js"] } } diff --git a/test/_helpers.js b/test/_helpers.js index f68328f..be28901 100644 --- a/test/_helpers.js +++ b/test/_helpers.js @@ -1,8 +1,66 @@ import path from 'path' +import mockery from 'mockery' +import Roots from 'roots' import RootsUtil from 'roots-util' +import ava from 'ava' -let helpers = new RootsUtil.Helpers({ +// polyfill array includes because of +// https://github.com/sindresorhus/ava/issues/263 +/* eslint-disable */ +Array.prototype.includes = do { + typeof Array.prototype.includes === 'function' + ? Array.prototype.includes + : function includes (needle) { + return this.indexOf(needle) > -1 + } +} +/* eslint-enable */ + +export const test = ava + +export const helpers = new RootsUtil.Helpers({ base: path.join(__dirname, './fixtures') }) -export default helpers +export async function compile_fixture (name) { + this.public_dir = `${name}/public` + return await helpers.project.compile(Roots, name) +} + +export function unmock_contentful () { + mockery.deregisterAll() + return mockery.disable() +} + +export function mock_contentful (opts = {}) { + mockery.enable({ + warnOnUnregistered: false, + useCleanCache: true + }) + opts = { + entries: [{ + sys: { sys: 'data' }, + fields: { + title: 'Default Title', + body: 'Default Body' + } + }], + content_type: { + name: 'Blog Post', + displayField: 'title' + }, + ...opts + } + return mockery.registerMock('contentful', { + createClient () { + return { + contentType () { + return Promise.resolve(opts.content_type) + }, + entries () { + return Promise.resolve(opts.entries) + } + } + } + }) +} diff --git a/test/_setup.js b/test/_setup.js index b823774..0fc4989 100644 --- a/test/_setup.js +++ b/test/_setup.js @@ -1,58 +1,10 @@ -import mockery from 'mockery' -import Roots from 'roots' -import helpers from './_helpers' +require('babel-core/register') -// polyfill array includes because of -// https://github.com/sindresorhus/ava/issues/263 -/* eslint-disable */ -Array.prototype.includes = do { - typeof Array.prototype.includes === 'function' - ? Array.prototype.includes - : function includes (needle) { - return this.indexOf(needle) > -1 - } -} -/* eslint-enable */ +var helpers = require('./_helpers').helpers -export async function compile_fixture (name) { - this.public_dir = `${name}/public` - return await helpers.project.compile(Roots, name) -} +console.log('setting up...') -export function unmock_contentful () { - mockery.deregisterAll() - return mockery.disable() -} - -export function mock_contentful (opts = {}) { - mockery.enable({ - warnOnUnregistered: false, - useCleanCache: true - }) - opts = { - entries: [{ - sys: { sys: 'data' }, - fields: { - title: 'Default Title', - body: 'Default Body' - } - }], - content_type: { - name: 'Blog Post', - displayField: 'title' - }, - ...opts - } - return mockery.registerMock('contentful', { - createClient () { - return { - contentType () { - return Promise.resolve(opts.content_type) - }, - entries () { - return Promise.resolve(opts.entries) - } - } - } - }) -} +helpers.project.install_dependencies('*', function () { + console.log('done with setup') + process.exit(0) +}) diff --git a/test/_teardown.js b/test/_teardown.js new file mode 100644 index 0000000..1f5d39c --- /dev/null +++ b/test/_teardown.js @@ -0,0 +1,14 @@ +require('babel-core/register') + +var helpers = require('./_helpers').helpers + +console.log('performing cleanup...') + +helpers.project.remove_folders('**/public') + .then(function () { + console.log('done with cleanup') + process.exit(0) + }) + .catch(function (e) { + throw new Error(e.message) + }) diff --git a/test/basic-compile.js b/test/basic-compile.js index 8363a54..df50f87 100644 --- a/test/basic-compile.js +++ b/test/basic-compile.js @@ -1,17 +1,13 @@ -import test from 'ava' -import helpers from './_helpers' import { + test, + helpers, mock_contentful, unmock_contentful, compile_fixture -} from './_setup' +} from './_helpers' let ctx = {} -test.cb.before(t => { - helpers.project.install_dependencies('*', t.end) -}) - test.before(async t => { let title = 'Throw Some Ds' let body = 'Rich Boy selling crick' @@ -36,5 +32,4 @@ test('has contentful data available in views', t => { test.after(async t => { unmock_contentful() - await helpers.project.remove_folders('**/public') }) diff --git a/test/config.js b/test/config.js index 23aea03..d7f404f 100644 --- a/test/config.js +++ b/test/config.js @@ -1,17 +1,13 @@ -import test from 'ava' -import helpers from './_helpers' import { + test, + helpers, mock_contentful, unmock_contentful, compile_fixture -} from './_setup' +} from './_helpers' let ctx = {} -test.cb.before(t => { - helpers.project.install_dependencies('*', t.end) -}) - test.before(async t => { let title = 'Gatorade' let body = 'Yung Lean' @@ -40,5 +36,4 @@ test('allows the content type name to be set through a k/v object config', async test.after(async t => { unmock_contentful() - await helpers.project.remove_folders('**/public') }) diff --git a/test/contentful-content-type-fields.js b/test/contentful-content-type-fields.js index cdd9507..d92225c 100644 --- a/test/contentful-content-type-fields.js +++ b/test/contentful-content-type-fields.js @@ -1,17 +1,12 @@ -import test from 'ava' -import helpers from './_helpers' import { + test, mock_contentful, unmock_contentful, compile_fixture -} from './_setup' +} from './_helpers' let ctx = {} -test.cb.before(t => { - helpers.project.install_dependencies('*', t.end) -}) - test.before(async t => { mock_contentful({ entries: [{ @@ -26,5 +21,4 @@ test('should throw an error if `sys` is a field name', async t => { test.after(async t => { unmock_contentful() - await helpers.project.remove_folders('**/public') }) diff --git a/test/custom-name-for-view-helper-local.js b/test/custom-name-for-view-helper-local.js index 07a5894..559b5c3 100644 --- a/test/custom-name-for-view-helper-local.js +++ b/test/custom-name-for-view-helper-local.js @@ -1,17 +1,13 @@ -import test from 'ava' -import helpers from './_helpers' import { + test, + helpers, mock_contentful, unmock_contentful, compile_fixture -} from './_setup' +} from './_helpers' let ctx = {} -test.cb.before(t => { - helpers.project.install_dependencies('*', t.end) -}) - test.before(async t => { let title = 'Throw Some Ds' let body = 'Rich Boy selling crack' @@ -32,5 +28,4 @@ test('has contentful data available in views under a custom name', t => { test.after(async t => { unmock_contentful() - await helpers.project.remove_folders('**/public') }) diff --git a/test/data-manipulation-sort.js b/test/data-manipulation-sort.js index 39c035f..2be0084 100644 --- a/test/data-manipulation-sort.js +++ b/test/data-manipulation-sort.js @@ -1,17 +1,13 @@ -import test from 'ava' -import helpers from './_helpers' import { + test, + helpers, mock_contentful, unmock_contentful, compile_fixture -} from './_setup' +} from './_helpers' let ctx = {} -test.cb.before(t => { - helpers.project.install_dependencies('*', t.end) -}) - test.before(async t => { ctx.titles = ['Title C', 'Title B', 'Title A'] ctx.bodies = [ @@ -51,5 +47,4 @@ test('has written data as json', t => { test.after(async t => { unmock_contentful() - await helpers.project.remove_folders('**/public') }) diff --git a/test/data-manipulation-transform.js b/test/data-manipulation-transform.js index 4c50f00..ca85026 100644 --- a/test/data-manipulation-transform.js +++ b/test/data-manipulation-transform.js @@ -1,17 +1,13 @@ -import test from 'ava' -import helpers from './_helpers' import { + test, + helpers, mock_contentful, unmock_contentful, compile_fixture -} from './_setup' +} from './_helpers' let ctx = {} -test.cb.before(t => { - helpers.project.install_dependencies('*', t.end) -}) - test.before(async t => { ctx.titles = ['Title C', 'Title B', 'Title A'] ctx.bodies = [ @@ -54,5 +50,4 @@ test('has written data as json', t => { test.after(async t => { unmock_contentful() - await helpers.project.remove_folders('**/public') }) diff --git a/test/single-entry-views-clear-entry-locals-between-each-compile.js b/test/single-entry-views-clear-entry-locals-between-each-compile.js index fa49cba..41b8b35 100644 --- a/test/single-entry-views-clear-entry-locals-between-each-compile.js +++ b/test/single-entry-views-clear-entry-locals-between-each-compile.js @@ -1,17 +1,13 @@ -import test from 'ava' -import helpers from './_helpers' import { + test, + helpers, mock_contentful, unmock_contentful, compile_fixture -} from './_setup' +} from './_helpers' let ctx = {} -test.cb.before(t => { - helpers.project.install_dependencies('*', t.end) -}) - test.before(async t => { let title = 'Wow such doge' let body = 'such amaze' @@ -35,5 +31,4 @@ test("should not have first entry's content in second entry's single view", t => test.after(async t => { unmock_contentful() - await helpers.project.remove_folders('**/public') }) diff --git a/test/single-entry-views-custom-multi-path-function.js b/test/single-entry-views-custom-multi-path-function.js index 111ea3b..65da26b 100644 --- a/test/single-entry-views-custom-multi-path-function.js +++ b/test/single-entry-views-custom-multi-path-function.js @@ -1,19 +1,15 @@ import path from 'path' -import test from 'ava' import slugify from 'underscore.string/slugify' -import helpers from './_helpers' import { + test, + helpers, mock_contentful, unmock_contentful, compile_fixture -} from './_setup' +} from './_helpers' let ctx = {} -test.cb.before(t => { - helpers.project.install_dependencies('*', t.end) -}) - test.before(async t => { let titles = ['Real Talk', 'Fake Talk'] let bodies = [ @@ -56,5 +52,4 @@ test("sets _urls attribute to all of the entry's compiled files", t => { test.after(async t => { unmock_contentful() - await helpers.project.remove_folders('**/public') }) diff --git a/test/single-entry-views-custom-path-function.js b/test/single-entry-views-custom-path-function.js index 7a4b76d..fd08dff 100644 --- a/test/single-entry-views-custom-path-function.js +++ b/test/single-entry-views-custom-path-function.js @@ -1,17 +1,13 @@ -import test from 'ava' -import helpers from './_helpers' import { + test, + helpers, mock_contentful, unmock_contentful, compile_fixture -} from './_setup' +} from './_helpers' let ctx = {} -test.cb.before(t => { - helpers.project.install_dependencies('*', t.end) -}) - test.before(async t => { let title = 'Real Talk' let body = "I'm not about to sit up here, and argue about who's to blame." @@ -36,5 +32,4 @@ test('compiles a single entry file using custom path', t => { test.after(async t => { unmock_contentful() - await helpers.project.remove_folders('**/public') }) diff --git a/test/single-entry-views-default-path-function.js b/test/single-entry-views-default-path-function.js index df672f8..db485d0 100644 --- a/test/single-entry-views-default-path-function.js +++ b/test/single-entry-views-default-path-function.js @@ -1,17 +1,13 @@ -import test from 'ava' -import helpers from './_helpers' import { + test, + helpers, mock_contentful, unmock_contentful, compile_fixture -} from './_setup' +} from './_helpers' let ctx = {} -test.cb.before(t => { - helpers.project.install_dependencies('*', t.end) -}) - test.before(async t => { let title = 'Real Talk' let body = "I'm not about to sit up here, and argue about who's to blame." @@ -44,5 +40,4 @@ test('sets a _url attribute to allow links to each entry', t => { test.after(async t => { unmock_contentful() - await helpers.project.remove_folders('**/public') }) diff --git a/test/single-entry-views-image-view-helper-function.js b/test/single-entry-views-image-view-helper-function.js index a44f6a1..800803b 100644 --- a/test/single-entry-views-image-view-helper-function.js +++ b/test/single-entry-views-image-view-helper-function.js @@ -1,17 +1,13 @@ -import test from 'ava' -import helpers from './_helpers' import { + test, + helpers, mock_contentful, unmock_contentful, compile_fixture -} from './_setup' +} from './_helpers' let ctx = { img_path: 'http://dogesay.com/wow.jpg' } -test.cb.before(t => { - helpers.project.install_dependencies('*', t.end) -}) - test.before(async t => { mock_contentful({ entries: [{ @@ -32,5 +28,4 @@ test('adds query string params to the image', t => { test.after(async t => { unmock_contentful() - await helpers.project.remove_folders('**/public') }) diff --git a/test/write-as-json.js b/test/write-as-json.js index be44093..ec175ae 100644 --- a/test/write-as-json.js +++ b/test/write-as-json.js @@ -1,17 +1,13 @@ -import test from 'ava' -import helpers from './_helpers' import { + test, + helpers, mock_contentful, unmock_contentful, compile_fixture -} from './_setup' +} from './_helpers' let ctx = {} -test.cb.before(t => { - helpers.project.install_dependencies('*', t.end) -}) - test.before(async t => { let title = 'Throw Some Ds' let body = 'Rich Boy selling crick' @@ -38,5 +34,4 @@ test('has written data as json', t => { test.after(async t => { unmock_contentful() - await helpers.project.remove_folders('**/public') }) From 7fdf86f47ceb5f7b3045325ee8809dd73a635aa6 Mon Sep 17 00:00:00 2001 From: Declan de Wet Date: Wed, 6 Jan 2016 21:22:59 +0200 Subject: [PATCH 06/11] improve test performance --- test/_helpers.js | 3 --- test/_setup.js | 3 --- test/_teardown.js | 12 ++---------- test/basic-compile.js | 2 +- test/config.js | 2 +- test/contentful-content-type-fields.js | 2 +- test/custom-name-for-view-helper-local.js | 2 +- test/data-manipulation-sort.js | 2 +- test/data-manipulation-transform.js | 2 +- ...-views-clear-entry-locals-between-each-compile.js | 2 +- .../single-entry-views-custom-multi-path-function.js | 2 +- test/single-entry-views-custom-path-function.js | 2 +- test/single-entry-views-default-path-function.js | 2 +- .../single-entry-views-image-view-helper-function.js | 2 +- test/write-as-json.js | 2 +- 15 files changed, 14 insertions(+), 28 deletions(-) diff --git a/test/_helpers.js b/test/_helpers.js index be28901..c60f972 100644 --- a/test/_helpers.js +++ b/test/_helpers.js @@ -2,7 +2,6 @@ import path from 'path' import mockery from 'mockery' import Roots from 'roots' import RootsUtil from 'roots-util' -import ava from 'ava' // polyfill array includes because of // https://github.com/sindresorhus/ava/issues/263 @@ -16,8 +15,6 @@ Array.prototype.includes = do { } /* eslint-enable */ -export const test = ava - export const helpers = new RootsUtil.Helpers({ base: path.join(__dirname, './fixtures') }) diff --git a/test/_setup.js b/test/_setup.js index 0fc4989..ad06ce6 100644 --- a/test/_setup.js +++ b/test/_setup.js @@ -1,9 +1,6 @@ require('babel-core/register') - var helpers = require('./_helpers').helpers - console.log('setting up...') - helpers.project.install_dependencies('*', function () { console.log('done with setup') process.exit(0) diff --git a/test/_teardown.js b/test/_teardown.js index 1f5d39c..ce5bc7e 100644 --- a/test/_teardown.js +++ b/test/_teardown.js @@ -1,14 +1,6 @@ require('babel-core/register') - var helpers = require('./_helpers').helpers - console.log('performing cleanup...') - helpers.project.remove_folders('**/public') - .then(function () { - console.log('done with cleanup') - process.exit(0) - }) - .catch(function (e) { - throw new Error(e.message) - }) +console.log('done with cleanup') +process.exit(0) diff --git a/test/basic-compile.js b/test/basic-compile.js index df50f87..3311955 100644 --- a/test/basic-compile.js +++ b/test/basic-compile.js @@ -1,5 +1,5 @@ +import test from 'ava' import { - test, helpers, mock_contentful, unmock_contentful, diff --git a/test/config.js b/test/config.js index d7f404f..9a96309 100644 --- a/test/config.js +++ b/test/config.js @@ -1,5 +1,5 @@ +import test from 'ava' import { - test, helpers, mock_contentful, unmock_contentful, diff --git a/test/contentful-content-type-fields.js b/test/contentful-content-type-fields.js index d92225c..dcfbbcc 100644 --- a/test/contentful-content-type-fields.js +++ b/test/contentful-content-type-fields.js @@ -1,5 +1,5 @@ +import test from 'ava' import { - test, mock_contentful, unmock_contentful, compile_fixture diff --git a/test/custom-name-for-view-helper-local.js b/test/custom-name-for-view-helper-local.js index 559b5c3..43ba1b0 100644 --- a/test/custom-name-for-view-helper-local.js +++ b/test/custom-name-for-view-helper-local.js @@ -1,5 +1,5 @@ +import test from 'ava' import { - test, helpers, mock_contentful, unmock_contentful, diff --git a/test/data-manipulation-sort.js b/test/data-manipulation-sort.js index 2be0084..db5af12 100644 --- a/test/data-manipulation-sort.js +++ b/test/data-manipulation-sort.js @@ -1,5 +1,5 @@ +import test from 'ava' import { - test, helpers, mock_contentful, unmock_contentful, diff --git a/test/data-manipulation-transform.js b/test/data-manipulation-transform.js index ca85026..72bfaef 100644 --- a/test/data-manipulation-transform.js +++ b/test/data-manipulation-transform.js @@ -1,5 +1,5 @@ +import test from 'ava' import { - test, helpers, mock_contentful, unmock_contentful, diff --git a/test/single-entry-views-clear-entry-locals-between-each-compile.js b/test/single-entry-views-clear-entry-locals-between-each-compile.js index 41b8b35..5630de9 100644 --- a/test/single-entry-views-clear-entry-locals-between-each-compile.js +++ b/test/single-entry-views-clear-entry-locals-between-each-compile.js @@ -1,5 +1,5 @@ +import test from 'ava' import { - test, helpers, mock_contentful, unmock_contentful, diff --git a/test/single-entry-views-custom-multi-path-function.js b/test/single-entry-views-custom-multi-path-function.js index 65da26b..78bcb83 100644 --- a/test/single-entry-views-custom-multi-path-function.js +++ b/test/single-entry-views-custom-multi-path-function.js @@ -1,7 +1,7 @@ import path from 'path' import slugify from 'underscore.string/slugify' +import test from 'ava' import { - test, helpers, mock_contentful, unmock_contentful, diff --git a/test/single-entry-views-custom-path-function.js b/test/single-entry-views-custom-path-function.js index fd08dff..3e38221 100644 --- a/test/single-entry-views-custom-path-function.js +++ b/test/single-entry-views-custom-path-function.js @@ -1,5 +1,5 @@ +import test from 'ava' import { - test, helpers, mock_contentful, unmock_contentful, diff --git a/test/single-entry-views-default-path-function.js b/test/single-entry-views-default-path-function.js index db485d0..10953dc 100644 --- a/test/single-entry-views-default-path-function.js +++ b/test/single-entry-views-default-path-function.js @@ -1,5 +1,5 @@ +import test from 'ava' import { - test, helpers, mock_contentful, unmock_contentful, diff --git a/test/single-entry-views-image-view-helper-function.js b/test/single-entry-views-image-view-helper-function.js index 800803b..e093eab 100644 --- a/test/single-entry-views-image-view-helper-function.js +++ b/test/single-entry-views-image-view-helper-function.js @@ -1,5 +1,5 @@ +import test from 'ava' import { - test, helpers, mock_contentful, unmock_contentful, diff --git a/test/write-as-json.js b/test/write-as-json.js index ec175ae..46c4136 100644 --- a/test/write-as-json.js +++ b/test/write-as-json.js @@ -1,5 +1,5 @@ +import test from 'ava' import { - test, helpers, mock_contentful, unmock_contentful, From c726997b71e1d8a0d9f193e31696d5492479c9e6 Mon Sep 17 00:00:00 2001 From: Declan de Wet Date: Thu, 7 Jan 2016 14:00:39 +0200 Subject: [PATCH 07/11] assert error messages --- test/config.js | 10 ++++++++-- test/contentful-content-type-fields.js | 5 ++++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/test/config.js b/test/config.js index 9a96309..e2d2fbd 100644 --- a/test/config.js +++ b/test/config.js @@ -20,11 +20,17 @@ test.before(async t => { }) test('should throw an error when missing an access token', async t => { - t.throws(ctx::compile_fixture('missing_token')) + t.throws( + ctx::compile_fixture('missing_token'), + 'Missing required options for roots-contentful. Please ensure `access_token` and `space_id` are present.' + ) }) test('should throw an error without content type id', async t => { - t.throws(ctx::compile_fixture('missing_config')) + t.throws( + ctx::compile_fixture('missing_config'), + 'One or more of your content types is missing an `id` value' + ) }) test('allows the content type name to be set through a k/v object config', async t => { diff --git a/test/contentful-content-type-fields.js b/test/contentful-content-type-fields.js index dcfbbcc..9d5c2ff 100644 --- a/test/contentful-content-type-fields.js +++ b/test/contentful-content-type-fields.js @@ -16,7 +16,10 @@ test.before(async t => { }) test('should throw an error if `sys` is a field name', async t => { - t.throws(ctx::compile_fixture('basic')) + t.throws( + ctx::compile_fixture('basic'), + 'One of your content types has `sys` as a field. This is reserved for storing Contentful system metadata, please rename this field to a different value.' + ) }) test.after(async t => { From 68c71deaee25091e910bc38f4a5a01bf4dc9a5e8 Mon Sep 17 00:00:00 2001 From: Declan de Wet Date: Thu, 7 Jan 2016 14:17:20 +0200 Subject: [PATCH 08/11] fix flaky coverage commands --- Makefile | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 844d2c5..7d37720 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ build: npm run build -coverage: +coverage:: npm run coverage coveralls: diff --git a/package.json b/package.json index 80aba09..7e9df0f 100644 --- a/package.json +++ b/package.json @@ -69,7 +69,7 @@ "posttest": "node test/_teardown.js", "prebuild": "npm test", "precommit": "npm run lint -s", - "precoverage": "nyc npm test", + "precoverage": "npm run test", "precoveralls": "npm run coverage", "prerelease": "npm run build", "pretest": "npm run lint -s && node test/_setup.js", From 2ce532077bbe7d5176bbf967da0192f01dfca83f Mon Sep 17 00:00:00 2001 From: Declan de Wet Date: Thu, 7 Jan 2016 15:17:40 +0200 Subject: [PATCH 09/11] re-use error message variables in tests --- test/config.js | 11 +++-------- test/contentful-content-type-fields.js | 6 ++---- 2 files changed, 5 insertions(+), 12 deletions(-) diff --git a/test/config.js b/test/config.js index e2d2fbd..88d6ea6 100644 --- a/test/config.js +++ b/test/config.js @@ -1,4 +1,5 @@ import test from 'ava' +import errors from '../src/errors' import { helpers, mock_contentful, @@ -20,17 +21,11 @@ test.before(async t => { }) test('should throw an error when missing an access token', async t => { - t.throws( - ctx::compile_fixture('missing_token'), - 'Missing required options for roots-contentful. Please ensure `access_token` and `space_id` are present.' - ) + t.throws(ctx::compile_fixture('missing_token'), errors.no_token) }) test('should throw an error without content type id', async t => { - t.throws( - ctx::compile_fixture('missing_config'), - 'One or more of your content types is missing an `id` value' - ) + t.throws(ctx::compile_fixture('missing_config'), errors.no_type_id) }) test('allows the content type name to be set through a k/v object config', async t => { diff --git a/test/contentful-content-type-fields.js b/test/contentful-content-type-fields.js index 9d5c2ff..2bfbcc6 100644 --- a/test/contentful-content-type-fields.js +++ b/test/contentful-content-type-fields.js @@ -1,4 +1,5 @@ import test from 'ava' +import errors from '../src/errors' import { mock_contentful, unmock_contentful, @@ -16,10 +17,7 @@ test.before(async t => { }) test('should throw an error if `sys` is a field name', async t => { - t.throws( - ctx::compile_fixture('basic'), - 'One of your content types has `sys` as a field. This is reserved for storing Contentful system metadata, please rename this field to a different value.' - ) + t.throws(ctx::compile_fixture('basic'), errors.sys_conflict) }) test.after(async t => { From 24130459dbd605383ab9d97b51e4b8dbfaf3f804 Mon Sep 17 00:00:00 2001 From: Declan de Wet Date: Thu, 7 Jan 2016 20:08:49 +0200 Subject: [PATCH 10/11] update ava, end class props with semicolon, ensure tests don't modify the same fixture --- package.json | 2 +- src/extension.js | 2 +- test/_setup.js | 2 +- test/_teardown.js | 2 +- test/{basic-compile.js => basic/compile.js} | 4 ++-- .../content-type-fields.js} | 6 +++--- .../custom-locals.js} | 4 ++-- test/config.js | 8 ++++---- .../sort.js} | 6 +++--- .../transform.js} | 6 +++--- .../{basic => basic--compile}/about.jade | 0 .../{basic => basic--compile}/app.coffee | 0 .../index.jade | 0 .../package.json | 0 .../basic--content-type-fields/about.jade | 1 + .../app.coffee | 0 .../index.jade | 0 .../package.json | 0 .../about.jade | 0 .../app.coffee | 0 .../index.jade | 0 .../package.json | 0 .../app.coffee | 0 .../index.jade | 0 .../package.json | 0 .../app.coffee | 0 .../index.jade | 0 .../package.json | 0 .../app.coffee | 0 .../index.jade | 0 .../package.json | 0 .../about.jade | 0 .../app.coffee | 0 .../index.jade | 0 .../package.json | 0 .../posts_expected.json | 0 .../about.jade | 0 .../app.coffee | 0 .../index.jade | 0 .../package.json | 0 .../posts_expected.json | 0 .../app.coffee | 0 .../index.jade | 0 .../package.json | 0 .../views/_blog_post.jade | 0 .../app.coffee | 0 .../index.jade | 0 .../package.json | 0 .../views/_blog_post.jade | 0 .../app.coffee | 20 +++++++++++++++++++ .../index.jade | 4 ++++ .../package.json | 0 .../views/_blog_post.jade | 3 +++ .../app.coffee | 18 +++++++++++++++++ .../index.jade | 0 .../package.json | 6 ++++++ .../app.coffee | 0 .../index.jade | 0 .../package.json | 0 .../views/_blog_post.jade | 0 .../{write => write--as-json}/about.jade | 0 .../{write => write--as-json}/app.coffee | 0 test/fixtures/write--as-json/index.jade | 5 +++++ test/fixtures/write--as-json/package.json | 6 ++++++ test/{_helpers.js => helpers/index.js} | 2 +- .../clear-locals-between-compiles.js} | 4 ++-- .../custom-path-function.js} | 4 ++-- .../default-path-function.js} | 4 ++-- .../image-view-helper.js} | 4 ++-- .../multi-path-function.js} | 4 ++-- test/{write-as-json.js => write.js} | 4 ++-- 71 files changed, 97 insertions(+), 34 deletions(-) rename test/{basic-compile.js => basic/compile.js} (91%) rename test/{contentful-content-type-fields.js => basic/content-type-fields.js} (70%) rename test/{custom-name-for-view-helper-local.js => basic/custom-locals.js} (89%) rename test/{data-manipulation-sort.js => data-manipulation/sort.js} (86%) rename test/{data-manipulation-transform.js => data-manipulation/transform.js} (86%) rename test/fixtures/{basic => basic--compile}/about.jade (100%) rename test/fixtures/{basic => basic--compile}/app.coffee (100%) rename test/fixtures/{alt-content-type-config => basic--compile}/index.jade (100%) rename test/fixtures/{alt-content-type-config => basic--compile}/package.json (100%) create mode 100644 test/fixtures/basic--content-type-fields/about.jade rename test/fixtures/{image_view_helper => basic--content-type-fields}/app.coffee (100%) rename test/fixtures/{basic => basic--content-type-fields}/index.jade (100%) rename test/fixtures/{basic => basic--content-type-fields}/package.json (100%) rename test/fixtures/{custom_name => basic--custom-locals}/about.jade (100%) rename test/fixtures/{custom_name => basic--custom-locals}/app.coffee (100%) rename test/fixtures/{custom_name => basic--custom-locals}/index.jade (100%) rename test/fixtures/{custom_name => basic--custom-locals}/package.json (100%) rename test/fixtures/{alt-content-type-config => config--alternative-type}/app.coffee (100%) rename test/fixtures/{missing_config => config--alternative-type}/index.jade (100%) rename test/fixtures/{image_view_helper => config--alternative-type}/package.json (100%) rename test/fixtures/{missing_config => config--missing-config}/app.coffee (100%) rename test/fixtures/{sort => config--missing-config}/index.jade (100%) rename test/fixtures/{missing_config => config--missing-config}/package.json (100%) rename test/fixtures/{missing_token => config--missing-token}/app.coffee (100%) rename test/fixtures/{missing_token => config--missing-token}/index.jade (100%) rename test/fixtures/{missing_token => config--missing-token}/package.json (100%) rename test/fixtures/{sort => data-manipulation--sort}/about.jade (100%) rename test/fixtures/{sort => data-manipulation--sort}/app.coffee (100%) rename test/fixtures/{transform => data-manipulation--sort}/index.jade (100%) rename test/fixtures/{single_entry => data-manipulation--sort}/package.json (100%) rename test/fixtures/{sort => data-manipulation--sort}/posts_expected.json (100%) rename test/fixtures/{transform => data-manipulation--transform}/about.jade (100%) rename test/fixtures/{transform => data-manipulation--transform}/app.coffee (100%) rename test/fixtures/{write => data-manipulation--transform}/index.jade (100%) rename test/fixtures/{sort => data-manipulation--transform}/package.json (100%) rename test/fixtures/{transform => data-manipulation--transform}/posts_expected.json (100%) rename test/fixtures/{single_entry => single-entry--clear-locals-between-compiles}/app.coffee (100%) rename test/fixtures/{single_entry => single-entry--clear-locals-between-compiles}/index.jade (100%) rename test/fixtures/{transform => single-entry--clear-locals-between-compiles}/package.json (100%) rename test/fixtures/{single_entry => single-entry--clear-locals-between-compiles}/views/_blog_post.jade (100%) rename test/fixtures/{single_entry_custom => single-entry--custom-path-function}/app.coffee (100%) rename test/fixtures/{single_entry_custom => single-entry--custom-path-function}/index.jade (100%) rename test/fixtures/{single_entry_custom => single-entry--custom-path-function}/package.json (100%) rename test/fixtures/{single_entry_custom => single-entry--custom-path-function}/views/_blog_post.jade (100%) create mode 100644 test/fixtures/single-entry--default-path-function/app.coffee create mode 100644 test/fixtures/single-entry--default-path-function/index.jade rename test/fixtures/{write => single-entry--default-path-function}/package.json (100%) create mode 100644 test/fixtures/single-entry--default-path-function/views/_blog_post.jade create mode 100644 test/fixtures/single-entry--image-view-helper/app.coffee rename test/fixtures/{image_view_helper => single-entry--image-view-helper}/index.jade (100%) create mode 100644 test/fixtures/single-entry--image-view-helper/package.json rename test/fixtures/{single_entry_multi => single-entry--multi-path-function}/app.coffee (100%) rename test/fixtures/{single_entry_multi => single-entry--multi-path-function}/index.jade (100%) rename test/fixtures/{single_entry_multi => single-entry--multi-path-function}/package.json (100%) rename test/fixtures/{single_entry_multi => single-entry--multi-path-function}/views/_blog_post.jade (100%) rename test/fixtures/{write => write--as-json}/about.jade (100%) rename test/fixtures/{write => write--as-json}/app.coffee (100%) create mode 100644 test/fixtures/write--as-json/index.jade create mode 100644 test/fixtures/write--as-json/package.json rename test/{_helpers.js => helpers/index.js} (96%) rename test/{single-entry-views-clear-entry-locals-between-each-compile.js => single-entry/clear-locals-between-compiles.js} (88%) rename test/{single-entry-views-custom-path-function.js => single-entry/custom-path-function.js} (90%) rename test/{single-entry-views-default-path-function.js => single-entry/default-path-function.js} (92%) rename test/{single-entry-views-image-view-helper-function.js => single-entry/image-view-helper.js} (87%) rename test/{single-entry-views-custom-multi-path-function.js => single-entry/multi-path-function.js} (94%) rename test/{write-as-json.js => write.js} (91%) diff --git a/package.json b/package.json index 7e9df0f..f89c442 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,7 @@ "underscore.string": "^3.2.2" }, "devDependencies": { - "ava": "sindresorhus/ava#65ae07c", + "ava": "^0.9.1", "babel-cli": "^6.3.15", "babel-core": "^6.3.26", "babel-eslint": "^4.1.6", diff --git a/src/extension.js b/src/extension.js index c16934b..cc806d5 100644 --- a/src/extension.js +++ b/src/extension.js @@ -21,7 +21,7 @@ export default class RootsContentful { cache: true, /* user-provided */ ...RootsContentful.opts - } + }; /** * @constructs RootsContentful diff --git a/test/_setup.js b/test/_setup.js index ad06ce6..25940be 100644 --- a/test/_setup.js +++ b/test/_setup.js @@ -1,5 +1,5 @@ require('babel-core/register') -var helpers = require('./_helpers').helpers +var helpers = require('./helpers').helpers console.log('setting up...') helpers.project.install_dependencies('*', function () { console.log('done with setup') diff --git a/test/_teardown.js b/test/_teardown.js index ce5bc7e..4de7aaa 100644 --- a/test/_teardown.js +++ b/test/_teardown.js @@ -1,5 +1,5 @@ require('babel-core/register') -var helpers = require('./_helpers').helpers +var helpers = require('./helpers').helpers console.log('performing cleanup...') helpers.project.remove_folders('**/public') console.log('done with cleanup') diff --git a/test/basic-compile.js b/test/basic/compile.js similarity index 91% rename from test/basic-compile.js rename to test/basic/compile.js index 3311955..13c09e1 100644 --- a/test/basic-compile.js +++ b/test/basic/compile.js @@ -4,7 +4,7 @@ import { mock_contentful, unmock_contentful, compile_fixture -} from './_helpers' +} from '../helpers' let ctx = {} @@ -17,7 +17,7 @@ test.before(async t => { fields: { title, body } }] }) - await ctx::compile_fixture('basic') + await ctx::compile_fixture('basic--compile') ctx.index_path = `${ctx.public_dir}/index.html` }) diff --git a/test/contentful-content-type-fields.js b/test/basic/content-type-fields.js similarity index 70% rename from test/contentful-content-type-fields.js rename to test/basic/content-type-fields.js index 2bfbcc6..ec0e0ea 100644 --- a/test/contentful-content-type-fields.js +++ b/test/basic/content-type-fields.js @@ -1,10 +1,10 @@ import test from 'ava' -import errors from '../src/errors' +import errors from '../../src/errors' import { mock_contentful, unmock_contentful, compile_fixture -} from './_helpers' +} from '../helpers' let ctx = {} @@ -17,7 +17,7 @@ test.before(async t => { }) test('should throw an error if `sys` is a field name', async t => { - t.throws(ctx::compile_fixture('basic'), errors.sys_conflict) + t.throws(ctx::compile_fixture('basic--content-type-fields'), errors.sys_conflict) }) test.after(async t => { diff --git a/test/custom-name-for-view-helper-local.js b/test/basic/custom-locals.js similarity index 89% rename from test/custom-name-for-view-helper-local.js rename to test/basic/custom-locals.js index 43ba1b0..081dc5a 100644 --- a/test/custom-name-for-view-helper-local.js +++ b/test/basic/custom-locals.js @@ -4,7 +4,7 @@ import { mock_contentful, unmock_contentful, compile_fixture -} from './_helpers' +} from '../helpers' let ctx = {} @@ -17,7 +17,7 @@ test.before(async t => { fields: { title, body } }] }) - await ctx::compile_fixture('custom_name') + await ctx::compile_fixture('basic--custom-locals') ctx.index_path = `${ctx.public_dir}/index.html` }) diff --git a/test/config.js b/test/config.js index 88d6ea6..56ddc63 100644 --- a/test/config.js +++ b/test/config.js @@ -5,7 +5,7 @@ import { mock_contentful, unmock_contentful, compile_fixture -} from './_helpers' +} from './helpers' let ctx = {} @@ -21,15 +21,15 @@ test.before(async t => { }) test('should throw an error when missing an access token', async t => { - t.throws(ctx::compile_fixture('missing_token'), errors.no_token) + t.throws(ctx::compile_fixture('config--missing-token'), errors.no_token) }) test('should throw an error without content type id', async t => { - t.throws(ctx::compile_fixture('missing_config'), errors.no_type_id) + t.throws(ctx::compile_fixture('config--missing-config'), errors.no_type_id) }) test('allows the content type name to be set through a k/v object config', async t => { - await ctx::compile_fixture('alt-content-type-config') + await ctx::compile_fixture('config--alternative-type') ctx.index_path = `${ctx.public_dir}/index.html` t.true(helpers.file.contains(ctx.index_path, ctx.title)) t.true(helpers.file.contains(ctx.index_path, ctx.body)) diff --git a/test/data-manipulation-sort.js b/test/data-manipulation/sort.js similarity index 86% rename from test/data-manipulation-sort.js rename to test/data-manipulation/sort.js index db5af12..79ee362 100644 --- a/test/data-manipulation-sort.js +++ b/test/data-manipulation/sort.js @@ -4,7 +4,7 @@ import { mock_contentful, unmock_contentful, compile_fixture -} from './_helpers' +} from '../helpers' let ctx = {} @@ -19,7 +19,7 @@ test.before(async t => { fields: { title, body: ctx.bodies[i] } })) mock_contentful({ entries: ctx.entries }) - await ctx::compile_fixture('sort') + await ctx::compile_fixture('data-manipulation--sort') ctx.index_path = `${ctx.public_dir}/index.html` ctx.posts_path = `${ctx.public_dir}/posts.json` }) @@ -42,7 +42,7 @@ test('orders data correctly for the project', t => { test('has written data as json', t => { t.ok(helpers.file.exists(ctx.posts_path)) - t.true(helpers.file.matches_file(ctx.posts_path, 'sort/posts_expected.json')) + t.true(helpers.file.matches_file(ctx.posts_path, 'data-manipulation--sort/posts_expected.json')) }) test.after(async t => { diff --git a/test/data-manipulation-transform.js b/test/data-manipulation/transform.js similarity index 86% rename from test/data-manipulation-transform.js rename to test/data-manipulation/transform.js index 72bfaef..16cd5fe 100644 --- a/test/data-manipulation-transform.js +++ b/test/data-manipulation/transform.js @@ -4,7 +4,7 @@ import { mock_contentful, unmock_contentful, compile_fixture -} from './_helpers' +} from '../helpers' let ctx = {} @@ -19,7 +19,7 @@ test.before(async t => { fields: { title, body: ctx.bodies[i] } })) mock_contentful({ entries: ctx.entries }) - await ctx::compile_fixture('transform') + await ctx::compile_fixture('data-manipulation--transform') ctx.index_path = `${ctx.public_dir}/index.html` ctx.posts_path = `${ctx.public_dir}/posts.json` }) @@ -45,7 +45,7 @@ test('has manipulated data correctly for the project', t => { test('has written data as json', t => { t.ok(helpers.file.exists(ctx.posts_path)) - t.true(helpers.file.matches_file(ctx.posts_path, 'transform/posts_expected.json')) + t.true(helpers.file.matches_file(ctx.posts_path, 'data-manipulation--transform/posts_expected.json')) }) test.after(async t => { diff --git a/test/fixtures/basic/about.jade b/test/fixtures/basic--compile/about.jade similarity index 100% rename from test/fixtures/basic/about.jade rename to test/fixtures/basic--compile/about.jade diff --git a/test/fixtures/basic/app.coffee b/test/fixtures/basic--compile/app.coffee similarity index 100% rename from test/fixtures/basic/app.coffee rename to test/fixtures/basic--compile/app.coffee diff --git a/test/fixtures/alt-content-type-config/index.jade b/test/fixtures/basic--compile/index.jade similarity index 100% rename from test/fixtures/alt-content-type-config/index.jade rename to test/fixtures/basic--compile/index.jade diff --git a/test/fixtures/alt-content-type-config/package.json b/test/fixtures/basic--compile/package.json similarity index 100% rename from test/fixtures/alt-content-type-config/package.json rename to test/fixtures/basic--compile/package.json diff --git a/test/fixtures/basic--content-type-fields/about.jade b/test/fixtures/basic--content-type-fields/about.jade new file mode 100644 index 0000000..2763786 --- /dev/null +++ b/test/fixtures/basic--content-type-fields/about.jade @@ -0,0 +1 @@ +h1 wow \ No newline at end of file diff --git a/test/fixtures/image_view_helper/app.coffee b/test/fixtures/basic--content-type-fields/app.coffee similarity index 100% rename from test/fixtures/image_view_helper/app.coffee rename to test/fixtures/basic--content-type-fields/app.coffee diff --git a/test/fixtures/basic/index.jade b/test/fixtures/basic--content-type-fields/index.jade similarity index 100% rename from test/fixtures/basic/index.jade rename to test/fixtures/basic--content-type-fields/index.jade diff --git a/test/fixtures/basic/package.json b/test/fixtures/basic--content-type-fields/package.json similarity index 100% rename from test/fixtures/basic/package.json rename to test/fixtures/basic--content-type-fields/package.json diff --git a/test/fixtures/custom_name/about.jade b/test/fixtures/basic--custom-locals/about.jade similarity index 100% rename from test/fixtures/custom_name/about.jade rename to test/fixtures/basic--custom-locals/about.jade diff --git a/test/fixtures/custom_name/app.coffee b/test/fixtures/basic--custom-locals/app.coffee similarity index 100% rename from test/fixtures/custom_name/app.coffee rename to test/fixtures/basic--custom-locals/app.coffee diff --git a/test/fixtures/custom_name/index.jade b/test/fixtures/basic--custom-locals/index.jade similarity index 100% rename from test/fixtures/custom_name/index.jade rename to test/fixtures/basic--custom-locals/index.jade diff --git a/test/fixtures/custom_name/package.json b/test/fixtures/basic--custom-locals/package.json similarity index 100% rename from test/fixtures/custom_name/package.json rename to test/fixtures/basic--custom-locals/package.json diff --git a/test/fixtures/alt-content-type-config/app.coffee b/test/fixtures/config--alternative-type/app.coffee similarity index 100% rename from test/fixtures/alt-content-type-config/app.coffee rename to test/fixtures/config--alternative-type/app.coffee diff --git a/test/fixtures/missing_config/index.jade b/test/fixtures/config--alternative-type/index.jade similarity index 100% rename from test/fixtures/missing_config/index.jade rename to test/fixtures/config--alternative-type/index.jade diff --git a/test/fixtures/image_view_helper/package.json b/test/fixtures/config--alternative-type/package.json similarity index 100% rename from test/fixtures/image_view_helper/package.json rename to test/fixtures/config--alternative-type/package.json diff --git a/test/fixtures/missing_config/app.coffee b/test/fixtures/config--missing-config/app.coffee similarity index 100% rename from test/fixtures/missing_config/app.coffee rename to test/fixtures/config--missing-config/app.coffee diff --git a/test/fixtures/sort/index.jade b/test/fixtures/config--missing-config/index.jade similarity index 100% rename from test/fixtures/sort/index.jade rename to test/fixtures/config--missing-config/index.jade diff --git a/test/fixtures/missing_config/package.json b/test/fixtures/config--missing-config/package.json similarity index 100% rename from test/fixtures/missing_config/package.json rename to test/fixtures/config--missing-config/package.json diff --git a/test/fixtures/missing_token/app.coffee b/test/fixtures/config--missing-token/app.coffee similarity index 100% rename from test/fixtures/missing_token/app.coffee rename to test/fixtures/config--missing-token/app.coffee diff --git a/test/fixtures/missing_token/index.jade b/test/fixtures/config--missing-token/index.jade similarity index 100% rename from test/fixtures/missing_token/index.jade rename to test/fixtures/config--missing-token/index.jade diff --git a/test/fixtures/missing_token/package.json b/test/fixtures/config--missing-token/package.json similarity index 100% rename from test/fixtures/missing_token/package.json rename to test/fixtures/config--missing-token/package.json diff --git a/test/fixtures/sort/about.jade b/test/fixtures/data-manipulation--sort/about.jade similarity index 100% rename from test/fixtures/sort/about.jade rename to test/fixtures/data-manipulation--sort/about.jade diff --git a/test/fixtures/sort/app.coffee b/test/fixtures/data-manipulation--sort/app.coffee similarity index 100% rename from test/fixtures/sort/app.coffee rename to test/fixtures/data-manipulation--sort/app.coffee diff --git a/test/fixtures/transform/index.jade b/test/fixtures/data-manipulation--sort/index.jade similarity index 100% rename from test/fixtures/transform/index.jade rename to test/fixtures/data-manipulation--sort/index.jade diff --git a/test/fixtures/single_entry/package.json b/test/fixtures/data-manipulation--sort/package.json similarity index 100% rename from test/fixtures/single_entry/package.json rename to test/fixtures/data-manipulation--sort/package.json diff --git a/test/fixtures/sort/posts_expected.json b/test/fixtures/data-manipulation--sort/posts_expected.json similarity index 100% rename from test/fixtures/sort/posts_expected.json rename to test/fixtures/data-manipulation--sort/posts_expected.json diff --git a/test/fixtures/transform/about.jade b/test/fixtures/data-manipulation--transform/about.jade similarity index 100% rename from test/fixtures/transform/about.jade rename to test/fixtures/data-manipulation--transform/about.jade diff --git a/test/fixtures/transform/app.coffee b/test/fixtures/data-manipulation--transform/app.coffee similarity index 100% rename from test/fixtures/transform/app.coffee rename to test/fixtures/data-manipulation--transform/app.coffee diff --git a/test/fixtures/write/index.jade b/test/fixtures/data-manipulation--transform/index.jade similarity index 100% rename from test/fixtures/write/index.jade rename to test/fixtures/data-manipulation--transform/index.jade diff --git a/test/fixtures/sort/package.json b/test/fixtures/data-manipulation--transform/package.json similarity index 100% rename from test/fixtures/sort/package.json rename to test/fixtures/data-manipulation--transform/package.json diff --git a/test/fixtures/transform/posts_expected.json b/test/fixtures/data-manipulation--transform/posts_expected.json similarity index 100% rename from test/fixtures/transform/posts_expected.json rename to test/fixtures/data-manipulation--transform/posts_expected.json diff --git a/test/fixtures/single_entry/app.coffee b/test/fixtures/single-entry--clear-locals-between-compiles/app.coffee similarity index 100% rename from test/fixtures/single_entry/app.coffee rename to test/fixtures/single-entry--clear-locals-between-compiles/app.coffee diff --git a/test/fixtures/single_entry/index.jade b/test/fixtures/single-entry--clear-locals-between-compiles/index.jade similarity index 100% rename from test/fixtures/single_entry/index.jade rename to test/fixtures/single-entry--clear-locals-between-compiles/index.jade diff --git a/test/fixtures/transform/package.json b/test/fixtures/single-entry--clear-locals-between-compiles/package.json similarity index 100% rename from test/fixtures/transform/package.json rename to test/fixtures/single-entry--clear-locals-between-compiles/package.json diff --git a/test/fixtures/single_entry/views/_blog_post.jade b/test/fixtures/single-entry--clear-locals-between-compiles/views/_blog_post.jade similarity index 100% rename from test/fixtures/single_entry/views/_blog_post.jade rename to test/fixtures/single-entry--clear-locals-between-compiles/views/_blog_post.jade diff --git a/test/fixtures/single_entry_custom/app.coffee b/test/fixtures/single-entry--custom-path-function/app.coffee similarity index 100% rename from test/fixtures/single_entry_custom/app.coffee rename to test/fixtures/single-entry--custom-path-function/app.coffee diff --git a/test/fixtures/single_entry_custom/index.jade b/test/fixtures/single-entry--custom-path-function/index.jade similarity index 100% rename from test/fixtures/single_entry_custom/index.jade rename to test/fixtures/single-entry--custom-path-function/index.jade diff --git a/test/fixtures/single_entry_custom/package.json b/test/fixtures/single-entry--custom-path-function/package.json similarity index 100% rename from test/fixtures/single_entry_custom/package.json rename to test/fixtures/single-entry--custom-path-function/package.json diff --git a/test/fixtures/single_entry_custom/views/_blog_post.jade b/test/fixtures/single-entry--custom-path-function/views/_blog_post.jade similarity index 100% rename from test/fixtures/single_entry_custom/views/_blog_post.jade rename to test/fixtures/single-entry--custom-path-function/views/_blog_post.jade diff --git a/test/fixtures/single-entry--default-path-function/app.coffee b/test/fixtures/single-entry--default-path-function/app.coffee new file mode 100644 index 0000000..b9d39a8 --- /dev/null +++ b/test/fixtures/single-entry--default-path-function/app.coffee @@ -0,0 +1,20 @@ +contentful = require '../../../src' + +module.exports = + ignores: ["**/_*", "**/.DS_Store"] + extensions: [ + contentful( + access_token: 'YOUR_ACCESS_TOKEN' + space_id: 'aqzq2qya2jm4' + content_types: [ + { + id: '6BYT1gNiIEyIw8Og8aQAO6' + name: 'blog_posts' + template: 'views/_blog_post.jade' + } + ] + ) + ] + + locals: + wow: 'such local' diff --git a/test/fixtures/single-entry--default-path-function/index.jade b/test/fixtures/single-entry--default-path-function/index.jade new file mode 100644 index 0000000..b881d53 --- /dev/null +++ b/test/fixtures/single-entry--default-path-function/index.jade @@ -0,0 +1,4 @@ +- for p in contentful.blog_posts + h1= p.title + p= p.body + a(href= p._url) Link diff --git a/test/fixtures/write/package.json b/test/fixtures/single-entry--default-path-function/package.json similarity index 100% rename from test/fixtures/write/package.json rename to test/fixtures/single-entry--default-path-function/package.json diff --git a/test/fixtures/single-entry--default-path-function/views/_blog_post.jade b/test/fixtures/single-entry--default-path-function/views/_blog_post.jade new file mode 100644 index 0000000..78a5b6c --- /dev/null +++ b/test/fixtures/single-entry--default-path-function/views/_blog_post.jade @@ -0,0 +1,3 @@ +h1= entry.title +p= entry.body +p= wow diff --git a/test/fixtures/single-entry--image-view-helper/app.coffee b/test/fixtures/single-entry--image-view-helper/app.coffee new file mode 100644 index 0000000..c2c261c --- /dev/null +++ b/test/fixtures/single-entry--image-view-helper/app.coffee @@ -0,0 +1,18 @@ +contentful = require '../../../src' + +module.exports = + ignores: ["**/_*", "**/.DS_Store"] + extensions: [ + contentful( + access_token: 'YOUR_ACCESS_TOKEN' + space_id: 'aqzq2qya2jm4' + content_types: [ + { + id: '6BYT1gNiIEyIw8Og8aQAO6' + } + { + id: '7CDlVsacqQc88cmIEGYWMa' + } + ] + ) + ] diff --git a/test/fixtures/image_view_helper/index.jade b/test/fixtures/single-entry--image-view-helper/index.jade similarity index 100% rename from test/fixtures/image_view_helper/index.jade rename to test/fixtures/single-entry--image-view-helper/index.jade diff --git a/test/fixtures/single-entry--image-view-helper/package.json b/test/fixtures/single-entry--image-view-helper/package.json new file mode 100644 index 0000000..2d0ae2c --- /dev/null +++ b/test/fixtures/single-entry--image-view-helper/package.json @@ -0,0 +1,6 @@ +{ + "name": "test", + "dependencies": { + "jade": "*" + } +} diff --git a/test/fixtures/single_entry_multi/app.coffee b/test/fixtures/single-entry--multi-path-function/app.coffee similarity index 100% rename from test/fixtures/single_entry_multi/app.coffee rename to test/fixtures/single-entry--multi-path-function/app.coffee diff --git a/test/fixtures/single_entry_multi/index.jade b/test/fixtures/single-entry--multi-path-function/index.jade similarity index 100% rename from test/fixtures/single_entry_multi/index.jade rename to test/fixtures/single-entry--multi-path-function/index.jade diff --git a/test/fixtures/single_entry_multi/package.json b/test/fixtures/single-entry--multi-path-function/package.json similarity index 100% rename from test/fixtures/single_entry_multi/package.json rename to test/fixtures/single-entry--multi-path-function/package.json diff --git a/test/fixtures/single_entry_multi/views/_blog_post.jade b/test/fixtures/single-entry--multi-path-function/views/_blog_post.jade similarity index 100% rename from test/fixtures/single_entry_multi/views/_blog_post.jade rename to test/fixtures/single-entry--multi-path-function/views/_blog_post.jade diff --git a/test/fixtures/write/about.jade b/test/fixtures/write--as-json/about.jade similarity index 100% rename from test/fixtures/write/about.jade rename to test/fixtures/write--as-json/about.jade diff --git a/test/fixtures/write/app.coffee b/test/fixtures/write--as-json/app.coffee similarity index 100% rename from test/fixtures/write/app.coffee rename to test/fixtures/write--as-json/app.coffee diff --git a/test/fixtures/write--as-json/index.jade b/test/fixtures/write--as-json/index.jade new file mode 100644 index 0000000..4769500 --- /dev/null +++ b/test/fixtures/write--as-json/index.jade @@ -0,0 +1,5 @@ +ul + - for p in contentful.blog_posts + li + h1= p.title + p= p.body diff --git a/test/fixtures/write--as-json/package.json b/test/fixtures/write--as-json/package.json new file mode 100644 index 0000000..2d0ae2c --- /dev/null +++ b/test/fixtures/write--as-json/package.json @@ -0,0 +1,6 @@ +{ + "name": "test", + "dependencies": { + "jade": "*" + } +} diff --git a/test/_helpers.js b/test/helpers/index.js similarity index 96% rename from test/_helpers.js rename to test/helpers/index.js index c60f972..2f9b392 100644 --- a/test/_helpers.js +++ b/test/helpers/index.js @@ -16,7 +16,7 @@ Array.prototype.includes = do { /* eslint-enable */ export const helpers = new RootsUtil.Helpers({ - base: path.join(__dirname, './fixtures') + base: path.join(__dirname, '../fixtures') }) export async function compile_fixture (name) { diff --git a/test/single-entry-views-clear-entry-locals-between-each-compile.js b/test/single-entry/clear-locals-between-compiles.js similarity index 88% rename from test/single-entry-views-clear-entry-locals-between-each-compile.js rename to test/single-entry/clear-locals-between-compiles.js index 5630de9..ae0cb98 100644 --- a/test/single-entry-views-clear-entry-locals-between-each-compile.js +++ b/test/single-entry/clear-locals-between-compiles.js @@ -4,7 +4,7 @@ import { mock_contentful, unmock_contentful, compile_fixture -} from './_helpers' +} from '../helpers' let ctx = {} @@ -20,7 +20,7 @@ test.before(async t => { ], content_type: { name: 'Blog Post', displayField: 'title' } }) - await ctx::compile_fixture('single_entry') + await ctx::compile_fixture('single-entry--clear-locals-between-compiles') ctx.index_path = `${ctx.public_dir}/index.html` ctx.post_path = `${ctx.public_dir}/blog_posts/totes-mcgotes.html` }) diff --git a/test/single-entry-views-custom-path-function.js b/test/single-entry/custom-path-function.js similarity index 90% rename from test/single-entry-views-custom-path-function.js rename to test/single-entry/custom-path-function.js index 3e38221..fa2d7ab 100644 --- a/test/single-entry-views-custom-path-function.js +++ b/test/single-entry/custom-path-function.js @@ -4,7 +4,7 @@ import { mock_contentful, unmock_contentful, compile_fixture -} from './_helpers' +} from '../helpers' let ctx = {} @@ -19,7 +19,7 @@ test.before(async t => { }], content_type: { name: 'Blog Post', displayField: 'title' } }) - await ctx::compile_fixture('single_entry_custom') + await ctx::compile_fixture('single-entry--custom-path-function') ctx.index_path = `${ctx.public_dir}/index.html` ctx.post_path = `${ctx.public_dir}/blogging/${ctx.category}/real-talk.html` }) diff --git a/test/single-entry-views-default-path-function.js b/test/single-entry/default-path-function.js similarity index 92% rename from test/single-entry-views-default-path-function.js rename to test/single-entry/default-path-function.js index 10953dc..5d48297 100644 --- a/test/single-entry-views-default-path-function.js +++ b/test/single-entry/default-path-function.js @@ -4,7 +4,7 @@ import { mock_contentful, unmock_contentful, compile_fixture -} from './_helpers' +} from '../helpers' let ctx = {} @@ -18,7 +18,7 @@ test.before(async t => { }], content_type: { name: 'Blog Post', displayField: 'title' } }) - await ctx::compile_fixture('single_entry') + await ctx::compile_fixture('single-entry--default-path-function') ctx.index_path = `${ctx.public_dir}/index.html` ctx.post_path = `${ctx.public_dir}/blog_posts/real-talk.html` }) diff --git a/test/single-entry-views-image-view-helper-function.js b/test/single-entry/image-view-helper.js similarity index 87% rename from test/single-entry-views-image-view-helper-function.js rename to test/single-entry/image-view-helper.js index e093eab..18d934a 100644 --- a/test/single-entry-views-image-view-helper-function.js +++ b/test/single-entry/image-view-helper.js @@ -4,7 +4,7 @@ import { mock_contentful, unmock_contentful, compile_fixture -} from './_helpers' +} from '../helpers' let ctx = { img_path: 'http://dogesay.com/wow.jpg' } @@ -18,7 +18,7 @@ test.before(async t => { } }] }) - await ctx::compile_fixture('image_view_helper') + await ctx::compile_fixture('single-entry--image-view-helper') ctx.index_path = `${ctx.public_dir}/index.html` }) diff --git a/test/single-entry-views-custom-multi-path-function.js b/test/single-entry/multi-path-function.js similarity index 94% rename from test/single-entry-views-custom-multi-path-function.js rename to test/single-entry/multi-path-function.js index 78bcb83..941b20e 100644 --- a/test/single-entry-views-custom-multi-path-function.js +++ b/test/single-entry/multi-path-function.js @@ -6,7 +6,7 @@ import { mock_contentful, unmock_contentful, compile_fixture -} from './_helpers' +} from '../helpers' let ctx = {} @@ -23,7 +23,7 @@ test.before(async t => { })), content_type: { name: 'Blog Post', displayField: 'title' } }) - await ctx::compile_fixture('single_entry_multi') + await ctx::compile_fixture('single-entry--multi-path-function') ctx.index_path = `${ctx.public_dir}/index.html` }) diff --git a/test/write-as-json.js b/test/write.js similarity index 91% rename from test/write-as-json.js rename to test/write.js index 46c4136..348db78 100644 --- a/test/write-as-json.js +++ b/test/write.js @@ -4,7 +4,7 @@ import { mock_contentful, unmock_contentful, compile_fixture -} from './_helpers' +} from './helpers' let ctx = {} @@ -17,7 +17,7 @@ test.before(async t => { fields: { title, body } }] }) - await ctx::compile_fixture('write') + await ctx::compile_fixture('write--as-json') ctx.index_path = `${ctx.public_dir}/index.html` ctx.posts_path = `${ctx.public_dir}/posts.json` }) From b0351a3fb7748dc0074fb0bf09c46667e4f9687b Mon Sep 17 00:00:00 2001 From: Elvin G Marmol Date: Fri, 8 Jan 2016 14:36:28 -0500 Subject: [PATCH 11/11] Make typeNames loop more concise --- src/extension.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/extension.js b/src/extension.js index cc806d5..7ae142e 100644 --- a/src/extension.js +++ b/src/extension.js @@ -196,10 +196,8 @@ async function set_urls (types) { async function set_reference_urls (types) { let pathFns = {} types = await Promise.all(types) - types.forEach((t) => { - if (t.path) { - pathFns[t.name] = { path: t.path } - } + types.forEach(({ path, name }) => { + if (path) pathFns[name] = { path } }) return types.map(({ template, content }) => { if (template) {