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/.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/Makefile b/Makefile index a6586d7..7d37720 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ build: npm run build -coverage: +coverage:: npm run coverage coveralls: @@ -12,3 +12,9 @@ release: lint: npm run lint + +debug-test: + npm run debug-test + +test:: + npm test 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/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..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", @@ -61,27 +61,23 @@ }, "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": "NODE_DEBUG=request npm run test -- --serial --verbose --fail-fast", "lint": "standard --verbose | snazzy", "postpublish": "git push --follow-tags", + "posttest": "node test/_teardown.js", "prebuild": "npm test", "precommit": "npm run lint -s", + "precoverage": "npm run test", "precoveralls": "npm run coverage", "prerelease": "npm run build", - "pretest": "npm run lint -s", + "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", - "globals": [ - "describe", - "it", - "before", - "after", - "beforeAll", - "afterAll" - ] + "ignore": ["test/_setup.js", "test/_teardown.js"] } } diff --git a/src/extension.js b/src/extension.js index e4e66de..7ae142e 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 @@ -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,60 @@ 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(({ path, name }) => { + if (path) pathFns[name] = { 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 diff --git a/test/_helpers.js b/test/_helpers.js deleted file mode 100644 index f68328f..0000000 --- a/test/_helpers.js +++ /dev/null @@ -1,8 +0,0 @@ -import path from 'path' -import RootsUtil from 'roots-util' - -let helpers = new RootsUtil.Helpers({ - base: path.join(__dirname, './fixtures') -}) - -export default helpers diff --git a/test/_setup.js b/test/_setup.js index b823774..25940be 100644 --- a/test/_setup.js +++ b/test/_setup.js @@ -1,58 +1,7 @@ -import mockery from 'mockery' -import Roots from 'roots' -import helpers from './_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 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) - } - } - } - }) -} +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 new file mode 100644 index 0000000..4de7aaa --- /dev/null +++ b/test/_teardown.js @@ -0,0 +1,6 @@ +require('babel-core/register') +var helpers = require('./helpers').helpers +console.log('performing cleanup...') +helpers.project.remove_folders('**/public') +console.log('done with cleanup') +process.exit(0) diff --git a/test/basic-compile.js b/test/basic/compile.js similarity index 75% rename from test/basic-compile.js rename to test/basic/compile.js index 8363a54..13c09e1 100644 --- a/test/basic-compile.js +++ b/test/basic/compile.js @@ -1,17 +1,13 @@ import test from 'ava' -import helpers from './_helpers' import { + 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' @@ -21,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` }) @@ -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/contentful-content-type-fields.js b/test/basic/content-type-fields.js similarity index 60% rename from test/contentful-content-type-fields.js rename to test/basic/content-type-fields.js index cdd9507..ec0e0ea 100644 --- a/test/contentful-content-type-fields.js +++ b/test/basic/content-type-fields.js @@ -1,17 +1,13 @@ import test from 'ava' -import helpers from './_helpers' +import errors from '../../src/errors' import { 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: [{ @@ -21,10 +17,9 @@ 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--content-type-fields'), errors.sys_conflict) }) 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/basic/custom-locals.js similarity index 73% rename from test/custom-name-for-view-helper-local.js rename to test/basic/custom-locals.js index 07a5894..081dc5a 100644 --- a/test/custom-name-for-view-helper-local.js +++ b/test/basic/custom-locals.js @@ -1,17 +1,13 @@ import test from 'ava' -import helpers from './_helpers' import { + 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' @@ -21,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` }) @@ -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/config.js b/test/config.js index 23aea03..56ddc63 100644 --- a/test/config.js +++ b/test/config.js @@ -1,17 +1,14 @@ import test from 'ava' -import helpers from './_helpers' +import errors from '../src/errors' import { + 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' @@ -24,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')) + 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')) + 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)) @@ -40,5 +37,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/data-manipulation-sort.js b/test/data-manipulation/sort.js similarity index 78% rename from test/data-manipulation-sort.js rename to test/data-manipulation/sort.js index 39c035f..79ee362 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 { + 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 = [ @@ -23,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` }) @@ -46,10 +42,9 @@ 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 => { unmock_contentful() - await helpers.project.remove_folders('**/public') }) diff --git a/test/data-manipulation-transform.js b/test/data-manipulation/transform.js similarity index 78% rename from test/data-manipulation-transform.js rename to test/data-manipulation/transform.js index 4c50f00..16cd5fe 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 { + 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 = [ @@ -23,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` }) @@ -49,10 +45,9 @@ 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 => { unmock_contentful() - await helpers.project.remove_folders('**/public') }) diff --git a/test/fixtures/alt-content-type-config/app.coffee b/test/fixtures/alt-content-type-config/app.coffee deleted file mode 100644 index c3d2b72..0000000 --- a/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/basic/about.jade b/test/fixtures/basic--compile/about.jade similarity index 100% rename from old_test/fixtures/basic/about.jade rename to test/fixtures/basic--compile/about.jade diff --git a/old_test/fixtures/basic/app.coffee b/test/fixtures/basic--compile/app.coffee similarity index 100% rename from old_test/fixtures/basic/app.coffee rename to test/fixtures/basic--compile/app.coffee diff --git a/old_test/fixtures/alt-content-type-config/index.jade b/test/fixtures/basic--compile/index.jade similarity index 100% rename from old_test/fixtures/alt-content-type-config/index.jade rename to test/fixtures/basic--compile/index.jade diff --git a/old_test/fixtures/alt-content-type-config/package.json b/test/fixtures/basic--compile/package.json similarity index 100% rename from old_test/fixtures/alt-content-type-config/package.json rename to test/fixtures/basic--compile/package.json diff --git a/test/fixtures/basic/about.jade b/test/fixtures/basic--content-type-fields/about.jade similarity index 100% rename from test/fixtures/basic/about.jade rename to test/fixtures/basic--content-type-fields/about.jade diff --git a/old_test/fixtures/image_view_helper/app.coffee b/test/fixtures/basic--content-type-fields/app.coffee similarity index 100% rename from old_test/fixtures/image_view_helper/app.coffee rename to test/fixtures/basic--content-type-fields/app.coffee diff --git a/old_test/fixtures/basic/index.jade b/test/fixtures/basic--content-type-fields/index.jade similarity index 100% rename from old_test/fixtures/basic/index.jade rename to test/fixtures/basic--content-type-fields/index.jade diff --git a/old_test/fixtures/basic/package.json b/test/fixtures/basic--content-type-fields/package.json similarity index 100% rename from old_test/fixtures/basic/package.json rename to test/fixtures/basic--content-type-fields/package.json diff --git a/old_test/fixtures/custom_name/about.jade b/test/fixtures/basic--custom-locals/about.jade similarity index 100% rename from old_test/fixtures/custom_name/about.jade rename to test/fixtures/basic--custom-locals/about.jade diff --git a/old_test/fixtures/custom_name/app.coffee b/test/fixtures/basic--custom-locals/app.coffee similarity index 100% rename from old_test/fixtures/custom_name/app.coffee rename to test/fixtures/basic--custom-locals/app.coffee diff --git a/old_test/fixtures/custom_name/index.jade b/test/fixtures/basic--custom-locals/index.jade similarity index 100% rename from old_test/fixtures/custom_name/index.jade rename to test/fixtures/basic--custom-locals/index.jade diff --git a/old_test/fixtures/custom_name/package.json b/test/fixtures/basic--custom-locals/package.json similarity index 100% rename from old_test/fixtures/custom_name/package.json rename to test/fixtures/basic--custom-locals/package.json diff --git a/test/fixtures/basic/index.jade b/test/fixtures/basic/index.jade deleted file mode 100644 index 4769500..0000000 --- a/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/alt-content-type-config/app.coffee b/test/fixtures/config--alternative-type/app.coffee similarity index 100% rename from old_test/fixtures/alt-content-type-config/app.coffee rename to test/fixtures/config--alternative-type/app.coffee diff --git a/old_test/fixtures/missing_config/index.jade b/test/fixtures/config--alternative-type/index.jade similarity index 100% rename from old_test/fixtures/missing_config/index.jade rename to test/fixtures/config--alternative-type/index.jade diff --git a/old_test/fixtures/image_view_helper/package.json b/test/fixtures/config--alternative-type/package.json similarity index 100% rename from old_test/fixtures/image_view_helper/package.json rename to test/fixtures/config--alternative-type/package.json diff --git a/old_test/fixtures/missing_config/app.coffee b/test/fixtures/config--missing-config/app.coffee similarity index 100% rename from old_test/fixtures/missing_config/app.coffee rename to test/fixtures/config--missing-config/app.coffee diff --git a/old_test/fixtures/sort/index.jade b/test/fixtures/config--missing-config/index.jade similarity index 100% rename from old_test/fixtures/sort/index.jade rename to test/fixtures/config--missing-config/index.jade diff --git a/old_test/fixtures/missing_config/package.json b/test/fixtures/config--missing-config/package.json similarity index 100% rename from old_test/fixtures/missing_config/package.json rename to test/fixtures/config--missing-config/package.json diff --git a/old_test/fixtures/missing_token/app.coffee b/test/fixtures/config--missing-token/app.coffee similarity index 100% rename from old_test/fixtures/missing_token/app.coffee rename to test/fixtures/config--missing-token/app.coffee diff --git a/old_test/fixtures/missing_token/index.jade b/test/fixtures/config--missing-token/index.jade similarity index 100% rename from old_test/fixtures/missing_token/index.jade rename to test/fixtures/config--missing-token/index.jade diff --git a/old_test/fixtures/missing_token/package.json b/test/fixtures/config--missing-token/package.json similarity index 100% rename from old_test/fixtures/missing_token/package.json rename to test/fixtures/config--missing-token/package.json diff --git a/test/fixtures/custom_name/about.jade b/test/fixtures/custom_name/about.jade deleted file mode 100644 index 8240f0e..0000000 --- a/test/fixtures/custom_name/about.jade +++ /dev/null @@ -1 +0,0 @@ -h1 wow diff --git a/test/fixtures/custom_name/app.coffee b/test/fixtures/custom_name/app.coffee deleted file mode 100644 index af220ac..0000000 --- a/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/test/fixtures/custom_name/index.jade b/test/fixtures/custom_name/index.jade deleted file mode 100644 index 190e01d..0000000 --- a/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/test/fixtures/custom_name/package.json b/test/fixtures/custom_name/package.json deleted file mode 100644 index 2d0ae2c..0000000 --- a/test/fixtures/custom_name/package.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "name": "test", - "dependencies": { - "jade": "*" - } -} diff --git a/old_test/fixtures/sort/about.jade b/test/fixtures/data-manipulation--sort/about.jade similarity index 100% rename from old_test/fixtures/sort/about.jade rename to test/fixtures/data-manipulation--sort/about.jade diff --git a/old_test/fixtures/sort/app.coffee b/test/fixtures/data-manipulation--sort/app.coffee similarity index 100% rename from old_test/fixtures/sort/app.coffee rename to test/fixtures/data-manipulation--sort/app.coffee diff --git a/old_test/fixtures/transform/index.jade b/test/fixtures/data-manipulation--sort/index.jade similarity index 100% rename from old_test/fixtures/transform/index.jade rename to test/fixtures/data-manipulation--sort/index.jade diff --git a/old_test/fixtures/single_entry/package.json b/test/fixtures/data-manipulation--sort/package.json similarity index 100% rename from old_test/fixtures/single_entry/package.json rename to test/fixtures/data-manipulation--sort/package.json diff --git a/old_test/fixtures/sort/posts_expected.json b/test/fixtures/data-manipulation--sort/posts_expected.json similarity index 100% rename from old_test/fixtures/sort/posts_expected.json rename to test/fixtures/data-manipulation--sort/posts_expected.json diff --git a/old_test/fixtures/transform/about.jade b/test/fixtures/data-manipulation--transform/about.jade similarity index 100% rename from old_test/fixtures/transform/about.jade rename to test/fixtures/data-manipulation--transform/about.jade diff --git a/old_test/fixtures/transform/app.coffee b/test/fixtures/data-manipulation--transform/app.coffee similarity index 100% rename from old_test/fixtures/transform/app.coffee rename to test/fixtures/data-manipulation--transform/app.coffee diff --git a/old_test/fixtures/write/index.jade b/test/fixtures/data-manipulation--transform/index.jade similarity index 100% rename from old_test/fixtures/write/index.jade rename to test/fixtures/data-manipulation--transform/index.jade diff --git a/old_test/fixtures/sort/package.json b/test/fixtures/data-manipulation--transform/package.json similarity index 100% rename from old_test/fixtures/sort/package.json rename to test/fixtures/data-manipulation--transform/package.json diff --git a/old_test/fixtures/transform/posts_expected.json b/test/fixtures/data-manipulation--transform/posts_expected.json similarity index 100% rename from old_test/fixtures/transform/posts_expected.json rename to test/fixtures/data-manipulation--transform/posts_expected.json diff --git a/test/fixtures/image_view_helper/app.coffee b/test/fixtures/image_view_helper/app.coffee deleted file mode 100644 index c2c261c..0000000 --- a/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/test/fixtures/image_view_helper/index.jade b/test/fixtures/image_view_helper/index.jade deleted file mode 100644 index 3eee69d..0000000 --- a/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/test/fixtures/image_view_helper/package.json b/test/fixtures/image_view_helper/package.json deleted file mode 100644 index 2d0ae2c..0000000 --- a/test/fixtures/image_view_helper/package.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "name": "test", - "dependencies": { - "jade": "*" - } -} diff --git a/test/fixtures/missing_config/app.coffee b/test/fixtures/missing_config/app.coffee deleted file mode 100644 index 2a318b6..0000000 --- a/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/test/fixtures/missing_config/index.jade b/test/fixtures/missing_config/index.jade deleted file mode 100644 index 4769500..0000000 --- a/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/test/fixtures/missing_config/package.json b/test/fixtures/missing_config/package.json deleted file mode 100644 index 2d0ae2c..0000000 --- a/test/fixtures/missing_config/package.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "name": "test", - "dependencies": { - "jade": "*" - } -} diff --git a/test/fixtures/missing_token/app.coffee b/test/fixtures/missing_token/app.coffee deleted file mode 100644 index 6b8b34a..0000000 --- a/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/test/fixtures/missing_token/index.jade b/test/fixtures/missing_token/index.jade deleted file mode 100644 index 8240f0e..0000000 --- a/test/fixtures/missing_token/index.jade +++ /dev/null @@ -1 +0,0 @@ -h1 wow diff --git a/test/fixtures/missing_token/package.json b/test/fixtures/missing_token/package.json deleted file mode 100644 index 2d0ae2c..0000000 --- a/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/test/fixtures/single-entry--clear-locals-between-compiles/app.coffee similarity index 100% rename from old_test/fixtures/single_entry/app.coffee rename to test/fixtures/single-entry--clear-locals-between-compiles/app.coffee diff --git a/old_test/fixtures/single_entry/index.jade b/test/fixtures/single-entry--clear-locals-between-compiles/index.jade similarity index 100% rename from old_test/fixtures/single_entry/index.jade rename to test/fixtures/single-entry--clear-locals-between-compiles/index.jade diff --git a/old_test/fixtures/transform/package.json b/test/fixtures/single-entry--clear-locals-between-compiles/package.json similarity index 100% rename from old_test/fixtures/transform/package.json rename to test/fixtures/single-entry--clear-locals-between-compiles/package.json diff --git a/old_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 old_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/old_test/fixtures/single_entry_custom/app.coffee b/test/fixtures/single-entry--custom-path-function/app.coffee similarity index 100% rename from old_test/fixtures/single_entry_custom/app.coffee rename to test/fixtures/single-entry--custom-path-function/app.coffee diff --git a/old_test/fixtures/single_entry_custom/index.jade b/test/fixtures/single-entry--custom-path-function/index.jade similarity index 100% rename from old_test/fixtures/single_entry_custom/index.jade rename to test/fixtures/single-entry--custom-path-function/index.jade diff --git a/old_test/fixtures/single_entry_custom/package.json b/test/fixtures/single-entry--custom-path-function/package.json similarity index 100% rename from old_test/fixtures/single_entry_custom/package.json rename to test/fixtures/single-entry--custom-path-function/package.json diff --git a/old_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 old_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/app.coffee b/test/fixtures/single-entry--default-path-function/app.coffee similarity index 100% rename from test/fixtures/single_entry/app.coffee rename to test/fixtures/single-entry--default-path-function/app.coffee diff --git a/test/fixtures/single_entry/index.jade b/test/fixtures/single-entry--default-path-function/index.jade similarity index 100% rename from test/fixtures/single_entry/index.jade rename to test/fixtures/single-entry--default-path-function/index.jade diff --git a/old_test/fixtures/write/package.json b/test/fixtures/single-entry--default-path-function/package.json similarity index 100% rename from old_test/fixtures/write/package.json rename to test/fixtures/single-entry--default-path-function/package.json diff --git a/test/fixtures/single_entry/views/_blog_post.jade b/test/fixtures/single-entry--default-path-function/views/_blog_post.jade similarity index 100% rename from test/fixtures/single_entry/views/_blog_post.jade rename to test/fixtures/single-entry--default-path-function/views/_blog_post.jade diff --git a/test/fixtures/basic/app.coffee b/test/fixtures/single-entry--image-view-helper/app.coffee similarity index 100% rename from test/fixtures/basic/app.coffee rename to test/fixtures/single-entry--image-view-helper/app.coffee diff --git a/old_test/fixtures/image_view_helper/index.jade b/test/fixtures/single-entry--image-view-helper/index.jade similarity index 100% rename from old_test/fixtures/image_view_helper/index.jade rename to test/fixtures/single-entry--image-view-helper/index.jade diff --git a/test/fixtures/alt-content-type-config/package.json b/test/fixtures/single-entry--image-view-helper/package.json similarity index 100% rename from test/fixtures/alt-content-type-config/package.json rename to test/fixtures/single-entry--image-view-helper/package.json diff --git a/old_test/fixtures/single_entry_multi/app.coffee b/test/fixtures/single-entry--multi-path-function/app.coffee similarity index 100% rename from old_test/fixtures/single_entry_multi/app.coffee rename to test/fixtures/single-entry--multi-path-function/app.coffee diff --git a/old_test/fixtures/single_entry_multi/index.jade b/test/fixtures/single-entry--multi-path-function/index.jade similarity index 100% rename from old_test/fixtures/single_entry_multi/index.jade rename to test/fixtures/single-entry--multi-path-function/index.jade diff --git a/old_test/fixtures/single_entry_multi/package.json b/test/fixtures/single-entry--multi-path-function/package.json similarity index 100% rename from old_test/fixtures/single_entry_multi/package.json rename to test/fixtures/single-entry--multi-path-function/package.json diff --git a/old_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 old_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/single_entry/package.json b/test/fixtures/single_entry/package.json deleted file mode 100644 index 2d0ae2c..0000000 --- a/test/fixtures/single_entry/package.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "name": "test", - "dependencies": { - "jade": "*" - } -} diff --git a/test/fixtures/single_entry_custom/app.coffee b/test/fixtures/single_entry_custom/app.coffee deleted file mode 100644 index a73a4bc..0000000 --- a/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/test/fixtures/single_entry_custom/index.jade b/test/fixtures/single_entry_custom/index.jade deleted file mode 100644 index 8240f0e..0000000 --- a/test/fixtures/single_entry_custom/index.jade +++ /dev/null @@ -1 +0,0 @@ -h1 wow diff --git a/test/fixtures/single_entry_custom/package.json b/test/fixtures/single_entry_custom/package.json deleted file mode 100644 index 1a248fc..0000000 --- a/test/fixtures/single_entry_custom/package.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "name": "test", - "dependencies": { - "jade": "*", - "underscore.string": "*" - } -} diff --git a/test/fixtures/single_entry_custom/views/_blog_post.jade b/test/fixtures/single_entry_custom/views/_blog_post.jade deleted file mode 100644 index 78a5b6c..0000000 --- a/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/test/fixtures/single_entry_multi/app.coffee b/test/fixtures/single_entry_multi/app.coffee deleted file mode 100644 index 503e364..0000000 --- a/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/test/fixtures/single_entry_multi/index.jade b/test/fixtures/single_entry_multi/index.jade deleted file mode 100644 index ee98265..0000000 --- a/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/test/fixtures/single_entry_multi/package.json b/test/fixtures/single_entry_multi/package.json deleted file mode 100644 index 1a248fc..0000000 --- a/test/fixtures/single_entry_multi/package.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "name": "test", - "dependencies": { - "jade": "*", - "underscore.string": "*" - } -} diff --git a/test/fixtures/single_entry_multi/views/_blog_post.jade b/test/fixtures/single_entry_multi/views/_blog_post.jade deleted file mode 100644 index 4355d6d..0000000 --- a/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/test/fixtures/sort/about.jade b/test/fixtures/sort/about.jade deleted file mode 100644 index 8240f0e..0000000 --- a/test/fixtures/sort/about.jade +++ /dev/null @@ -1 +0,0 @@ -h1 wow diff --git a/test/fixtures/sort/app.coffee b/test/fixtures/sort/app.coffee deleted file mode 100644 index 22f1105..0000000 --- a/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/test/fixtures/sort/index.jade b/test/fixtures/sort/index.jade deleted file mode 100644 index 4769500..0000000 --- a/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/test/fixtures/sort/package.json b/test/fixtures/sort/package.json deleted file mode 100644 index 2d0ae2c..0000000 --- a/test/fixtures/sort/package.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "name": "test", - "dependencies": { - "jade": "*" - } -} diff --git a/test/fixtures/sort/posts_expected.json b/test/fixtures/sort/posts_expected.json deleted file mode 100644 index 2801a26..0000000 --- a/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/test/fixtures/transform/about.jade b/test/fixtures/transform/about.jade deleted file mode 100644 index 8240f0e..0000000 --- a/test/fixtures/transform/about.jade +++ /dev/null @@ -1 +0,0 @@ -h1 wow diff --git a/test/fixtures/transform/app.coffee b/test/fixtures/transform/app.coffee deleted file mode 100644 index 68f04ec..0000000 --- a/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/test/fixtures/transform/index.jade b/test/fixtures/transform/index.jade deleted file mode 100644 index 4769500..0000000 --- a/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/test/fixtures/transform/package.json b/test/fixtures/transform/package.json deleted file mode 100644 index 2d0ae2c..0000000 --- a/test/fixtures/transform/package.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "name": "test", - "dependencies": { - "jade": "*" - } -} diff --git a/test/fixtures/transform/posts_expected.json b/test/fixtures/transform/posts_expected.json deleted file mode 100644 index 719b928..0000000 --- a/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/test/fixtures/write--as-json/about.jade similarity index 100% rename from old_test/fixtures/write/about.jade rename to test/fixtures/write--as-json/about.jade diff --git a/old_test/fixtures/write/app.coffee b/test/fixtures/write--as-json/app.coffee similarity index 100% rename from old_test/fixtures/write/app.coffee rename to test/fixtures/write--as-json/app.coffee diff --git a/test/fixtures/alt-content-type-config/index.jade b/test/fixtures/write--as-json/index.jade similarity index 100% rename from test/fixtures/alt-content-type-config/index.jade rename to test/fixtures/write--as-json/index.jade diff --git a/test/fixtures/basic/package.json b/test/fixtures/write--as-json/package.json similarity index 100% rename from test/fixtures/basic/package.json rename to test/fixtures/write--as-json/package.json diff --git a/test/fixtures/write/about.jade b/test/fixtures/write/about.jade deleted file mode 100644 index 8240f0e..0000000 --- a/test/fixtures/write/about.jade +++ /dev/null @@ -1 +0,0 @@ -h1 wow diff --git a/test/fixtures/write/app.coffee b/test/fixtures/write/app.coffee deleted file mode 100644 index 4bd0770..0000000 --- a/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/test/fixtures/write/index.jade b/test/fixtures/write/index.jade deleted file mode 100644 index 4769500..0000000 --- a/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/test/fixtures/write/package.json b/test/fixtures/write/package.json deleted file mode 100644 index 2d0ae2c..0000000 --- a/test/fixtures/write/package.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "name": "test", - "dependencies": { - "jade": "*" - } -} diff --git a/test/helpers/index.js b/test/helpers/index.js new file mode 100644 index 0000000..2f9b392 --- /dev/null +++ b/test/helpers/index.js @@ -0,0 +1,63 @@ +import path from 'path' +import mockery from 'mockery' +import Roots from 'roots' +import RootsUtil from 'roots-util' + +// 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 helpers = new RootsUtil.Helpers({ + base: path.join(__dirname, '../fixtures') +}) + +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/single-entry-views-clear-entry-locals-between-each-compile.js b/test/single-entry/clear-locals-between-compiles.js similarity index 77% rename from test/single-entry-views-clear-entry-locals-between-each-compile.js rename to test/single-entry/clear-locals-between-compiles.js index fa49cba..ae0cb98 100644 --- a/test/single-entry-views-clear-entry-locals-between-each-compile.js +++ b/test/single-entry/clear-locals-between-compiles.js @@ -1,17 +1,13 @@ import test from 'ava' -import helpers from './_helpers' import { + 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' @@ -24,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` }) @@ -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-path-function.js b/test/single-entry/custom-path-function.js similarity index 78% rename from test/single-entry-views-custom-path-function.js rename to test/single-entry/custom-path-function.js index 7a4b76d..fa2d7ab 100644 --- a/test/single-entry-views-custom-path-function.js +++ b/test/single-entry/custom-path-function.js @@ -1,17 +1,13 @@ import test from 'ava' -import helpers from './_helpers' import { + 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." @@ -23,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` }) @@ -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/default-path-function.js similarity index 83% rename from test/single-entry-views-default-path-function.js rename to test/single-entry/default-path-function.js index df672f8..5d48297 100644 --- a/test/single-entry-views-default-path-function.js +++ b/test/single-entry/default-path-function.js @@ -1,17 +1,13 @@ import test from 'ava' -import helpers from './_helpers' import { + 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." @@ -22,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` }) @@ -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/image-view-helper.js similarity index 70% rename from test/single-entry-views-image-view-helper-function.js rename to test/single-entry/image-view-helper.js index a44f6a1..18d934a 100644 --- a/test/single-entry-views-image-view-helper-function.js +++ b/test/single-entry/image-view-helper.js @@ -1,17 +1,13 @@ import test from 'ava' -import helpers from './_helpers' import { + 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: [{ @@ -22,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` }) @@ -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/single-entry-views-custom-multi-path-function.js b/test/single-entry/multi-path-function.js similarity index 86% rename from test/single-entry-views-custom-multi-path-function.js rename to test/single-entry/multi-path-function.js index 111ea3b..941b20e 100644 --- a/test/single-entry-views-custom-multi-path-function.js +++ b/test/single-entry/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 from 'ava' import { + 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 = [ @@ -27,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` }) @@ -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/write-as-json.js b/test/write.js similarity index 77% rename from test/write-as-json.js rename to test/write.js index be44093..348db78 100644 --- a/test/write-as-json.js +++ b/test/write.js @@ -1,17 +1,13 @@ import test from 'ava' -import helpers from './_helpers' import { + 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' @@ -21,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` }) @@ -38,5 +34,4 @@ test('has written data as json', t => { test.after(async t => { unmock_contentful() - await helpers.project.remove_folders('**/public') })