diff --git a/lib/contentful.js b/lib/contentful.js index aafa6c997..a702d3154 100644 --- a/lib/contentful.js +++ b/lib/contentful.js @@ -8,7 +8,8 @@ import axios from '@contentful/axios' import {createHttpClient, getUserAgentHeader} from 'contentful-sdk-core' import createContentfulApi from './create-contentful-api' -import createLinkResolver from './create-link-resolver' +import createGlobalOptions from './create-global-options' + /** * Create a client instance * @func @@ -50,7 +51,9 @@ export function createClient (params) { // Use resolveLinks param if specified, otherwise default to true const resolveLinks = !!('resolveLinks' in params ? params.resolveLinks : true) - const shouldLinksResolve = createLinkResolver(resolveLinks) + const removeUnresolved = !!params.removeUnresolved + + const getGlobalOptions = createGlobalOptions({resolveLinks, removeUnresolved}) const userAgentHeader = getUserAgentHeader(`contentful.js/${__VERSION__}`, params.application, params.integration @@ -66,6 +69,6 @@ export function createClient (params) { return createContentfulApi({ http: http, - shouldLinksResolve: shouldLinksResolve + getGlobalOptions: getGlobalOptions }) } diff --git a/lib/create-contentful-api.js b/lib/create-contentful-api.js index abe4f8b9e..bfedbde75 100644 --- a/lib/create-contentful-api.js +++ b/lib/create-contentful-api.js @@ -56,10 +56,10 @@ import pagedSync from './paged-sync' * @param {Object} params - API initialization params * @prop {Object} http - HTTP client instance * @prop {Object} entities - Object with wrapper methods for each kind of entity - * @prop {Function} shouldLinksResolve - Link resolver preconfigured with global setting + * @prop {Function} getGlobalOptions - Link resolver preconfigured with global setting * @return {ClientAPI} */ -export default function createContentfulApi ({http, shouldLinksResolve}) { +export default function createContentfulApi ({http, getGlobalOptions}) { const {wrapSpace} = entities.space const {wrapContentType, wrapContentTypeCollection} = entities.contentType const {wrapEntry, wrapEntryCollection} = entities.entry @@ -179,11 +179,10 @@ export default function createContentfulApi ({http, shouldLinksResolve}) { * .catch(console.error) */ function getEntries (query = {}) { - const resolveLinks = shouldLinksResolve(query) - const resolveForAllLocales = (query.locale && query.locale === '*') + const { resolveLinks, removeUnresolved } = getGlobalOptions(query) normalizeSelect(query) return http.get('entries', createRequestConfig({query: query})) - .then((response) => wrapEntryCollection(response.data, resolveLinks, resolveForAllLocales), errorHandler) + .then((response) => wrapEntryCollection(response.data, { resolveLinks, removeUnresolved }), errorHandler) } /** * Gets an Asset @@ -265,8 +264,8 @@ export default function createContentfulApi ({http, shouldLinksResolve}) { * .catch(console.error) */ function sync (query = {}) { - const resolveLinks = shouldLinksResolve(query) - return pagedSync(http, query, resolveLinks) + const { resolveLinks, removeUnresolved } = getGlobalOptions(query) + return pagedSync(http, query, { resolveLinks, removeUnresolved }) } /** @@ -300,7 +299,8 @@ export default function createContentfulApi ({http, shouldLinksResolve}) { * console.log( parsedData.items[0].fields.foo ); // foo */ function parseEntries (data) { - return wrapEntryCollection(data, true, false) + const { resolveLinks, removeUnresolved } = getGlobalOptions({}) + return wrapEntryCollection(data, { resolveLinks, removeUnresolved }) } /* * sdk relies heavily on sys metadata diff --git a/lib/create-link-resolver.js b/lib/create-global-options.js similarity index 71% rename from lib/create-link-resolver.js rename to lib/create-global-options.js index 384c40ef4..fb7117740 100644 --- a/lib/create-link-resolver.js +++ b/lib/create-global-options.js @@ -5,12 +5,12 @@ * @param {boolean} globalSetting - Global library setting for link resolution * @returns {function} Link resolver method preconfigured with global setting */ -export default function createLinkResolver (globalSetting) { +export default function createGlobalOptions (globalSettings) { /** * Link resolver method * @param {Object} query - regular query object used for collection endpoints */ - return function shouldLinksResolve (query) { - return !!('resolveLinks' in query ? query.resolveLinks : globalSetting) + return function getGlobalOptions (query) { + return Object.assign({}, globalSettings, query) } } diff --git a/lib/entities/entry.js b/lib/entities/entry.js index 5ee7e1b60..719ade384 100644 --- a/lib/entities/entry.js +++ b/lib/entities/entry.js @@ -1,7 +1,7 @@ import cloneDeep from 'lodash/cloneDeep' import {toPlainObject, freezeSys} from 'contentful-sdk-core' -import mixinLinkGetters from '../mixins/link-getters' import mixinStringifySafe from '../mixins/stringify-safe' +import resolveResponse from 'contentful-resolve-response' /** * Types of fields found in an Entry @@ -94,19 +94,13 @@ export function wrapEntry (data) { * Data is also mixed in with link getters if links exist and includes were requested * @private * @param {Object} data - Raw entry collection data + * @param {Object} options - wrapper options * @return {EntryCollection} Wrapped entry collection data */ -export function wrapEntryCollection (data, resolveLinks, resolveForAllLocales) { +export function wrapEntryCollection (data, {resolveLinks, removeUnresolved}) { const wrappedData = mixinStringifySafe(toPlainObject(cloneDeep(data))) if (resolveLinks) { - const includes = prepareIncludes(wrappedData.includes, wrappedData.items) - mixinLinkGetters(wrappedData.items, includes, resolveForAllLocales) + wrappedData.items = resolveResponse(wrappedData, {removeUnresolved}) } return freezeSys(wrappedData) } - -function prepareIncludes (includes = {}, items) { - includes.Entry = includes.Entry || [] - includes.Entry = [ ...new Set([...includes.Entry, ...items]) ] - return includes -} diff --git a/lib/mixins/link-getters.js b/lib/mixins/link-getters.js deleted file mode 100644 index 5cd5a7799..000000000 --- a/lib/mixins/link-getters.js +++ /dev/null @@ -1,104 +0,0 @@ -import memoize from 'lodash/memoize' - -/** - * Sets getters on links for a given response - * @private - * @param {Array} items - * @param {Object} includes - Object with lists of Entry, Asset, DeletedEntry and DeletedAsset - */ -export default function mixinLinkGetters (items, includes) { - const linkGetter = memoize(getLinksFromIncludes, memoizationResolver) - items.forEach((item) => { - if (item.fields) { - setLocalizedFieldGetters(item.fields, !!item.sys.locale) - } - }) - - /** - * If a field does not have a locale defined in sys, the content of that field - * is an object where the keys are each available locale, and we need to iterate - * over each of those - * @private - * @param {Object} fields - Fields object - * @param {boolean} hasLocale - If entry has been requested with a locale - */ - function setLocalizedFieldGetters (fields, hasLocale) { - if (hasLocale) { - setFieldGettersForFields(fields) - } else { - const fieldKeys = Object.keys(fields) - fieldKeys.forEach((fieldKey) => setFieldGettersForFields(fields[fieldKey])) - } - } - - /** - * Sets getters on each link field or list of link fields for each item - * @private - * @param {Object} fields - Fields object - */ - function setFieldGettersForFields (fields) { - const fieldKeys = Object.keys(fields) - fieldKeys.forEach((fieldKey) => { - const field = fields[fieldKey] - if (Array.isArray(field)) { - addGetterForLinkArray(field, fieldKey, fields) - } else { - addGetterForLink(field, fieldKey, fields) - } - }) - } - - /** - * Sets a getter which resolves the link of the given fieldKey in fields - * @private - * @param {Object} field - Field object - * @param {string} fieldKey - * @param {Object} fields - Fields object - */ - function addGetterForLink (field, fieldKey, fields) { - if (field !== null && typeof field === 'object' && field.hasOwnProperty('sys') && field.sys.hasOwnProperty('type') && field.sys.type === 'Link') { - Object.defineProperty(fields, fieldKey, { - get: () => linkGetter(field) - }) - } - } - - /** - * Sets a getter which resolves the array of links of the given fieldKey in fields - * @private - * @param {Array} field - List field array - * @param {string} fieldKey - * @param {Object} fields - Fields object - */ - function addGetterForLinkArray (listField, fieldKey, fields) { - if (listField.length && listField[0] !== null && typeof listField[0] === 'object' && listField[0].hasOwnProperty('sys') && listField[0].sys.hasOwnProperty('type') && listField[0].sys.type === 'Link') { - Object.defineProperty(fields, fieldKey, { - get: () => listField.map((field) => linkGetter(field)) - }) - } - } - - /** - * Looks for given link field in includes. - * If linked entity is not found, it returns the original link. - * This method shouldn't be used directly, and it's memoized whenever this - * module's main method is used. - * This is done to prevent the same link being resolved multiple times. - * @private - * @param {Object} field - Field object - * @return {Object} Field, or link if field not resolved - */ - function getLinksFromIncludes (field) { - const linkedEntities = includes[field.sys.linkType] || [] - const link = linkedEntities.find((linkedEntity) => linkedEntity.sys.id === field.sys.id) - if (link && link.fields) { - setLocalizedFieldGetters(link.fields, !!link.sys.locale) - return link - } - return field - } - - function memoizationResolver (link) { - return link.sys.id - } -} diff --git a/lib/paged-sync.js b/lib/paged-sync.js index 27458f49d..53e09187b 100644 --- a/lib/paged-sync.js +++ b/lib/paged-sync.js @@ -2,9 +2,8 @@ * See Synchronization for more information. * @namespace Sync */ -import cloneDeep from 'lodash/cloneDeep' import {createRequestConfig, freezeSys, toPlainObject} from 'contentful-sdk-core' -import mixinLinkGetters from './mixins/link-getters' +import resolveResponse from 'contentful-resolve-response' import mixinStringifySafe from './mixins/stringify-safe' /** @@ -41,7 +40,7 @@ import mixinStringifySafe from './mixins/stringify-safe' * @param {boolean} resolveLinks - If links should be resolved * @return {Promise} */ -export default function pagedSync (http, query, resolveLinks) { +export default function pagedSync (http, query, { resolveLinks, removeUnresolved }) { if (!query || (!query.initial && !query.nextSyncToken)) { throw new Error('Please provide one of `initial` or `nextSyncToken` parameters for syncing') } @@ -56,7 +55,7 @@ export default function pagedSync (http, query, resolveLinks) { .then((response) => { // clones response.items used in includes because we don't want these to be mutated if (resolveLinks) { - mixinLinkGetters(response.items, mapIncludeItems(cloneDeep(response.items))) + response.items = resolveResponse(response, {resolveLinks, removeUnresolved}) } // maps response items again after getters are attached const mappedResponseItems = mapResponseItems(response.items) @@ -81,20 +80,6 @@ function mapResponseItems (items) { } } -/** - * Creates an object similar to the one retrieved on `includes` from the `entries` - * endpoint, for usage with the link getters mixin - * @private - * @param {Array} items - * @return {Object} - */ -function mapIncludeItems (items) { - return { - Entry: items.filter((item) => item.sys.type === 'Entry'), - Asset: items.filter((item) => item.sys.type === 'Asset') - } -} - /** * If the response contains a nextPageUrl, extracts the sync token to get the * next page and calls itself again with that token. diff --git a/package.json b/package.json index 3b3e6b9ff..efb3ee256 100644 --- a/package.json +++ b/package.json @@ -27,11 +27,11 @@ "pretest": "rimraf coverage && npm run lint", "test": "npm run test:cover && npm run test:integration && npm run test:browser-local && npm run test:size", "test:ci": "npm run build && ./node_modules/contentful-sdk-core/bin/test-ci.sh", - "test:cover": "BABEL_ENV=test babel-node ./node_modules/istanbul/lib/cli.js cover ./test/runner | tap-spec", - "test:unit": "BABEL_ENV=test babel-node ./test/runner | tap-spec", - "test:debug": "BABEL_ENV=test babel-node debug ./test/runner", - "test:integration": "BABEL_ENV=test babel-node ./test/integration/tests.js | tap-spec", - "test:integration-debug": "BABEL_ENV=test babel-node debug ./test/integration/tests.js", + "test:cover": "BABEL_ENV=test node ./node_modules/istanbul/lib/cli.js cover ./test/runner | tap-spec", + "test:unit": "BABEL_ENV=test node ./test/runner | tap-spec", + "test:debug": "BABEL_ENV=test node debug ./test/runner", + "test:integration": "BABEL_ENV=test babel-node ./test/integration/runner.js | tap-spec", + "test:integration-debug": "BABEL_ENV=test babel-node debug ./test/integration/runner.js", "test:browser-local": "BABEL_ENV=test karma start karma.conf.local.js", "test:browser-remote": "BABEL_ENV=test karma start karma.conf.saucelabs.js", "test:e2e": "node test/e2e/index.js", @@ -58,6 +58,7 @@ ], "dependencies": { "@contentful/axios": "^0.18.0", + "contentful-resolve-response": "^1.0.0", "contentful-sdk-core": "^5.0.1", "json-stringify-safe": "^5.0.1", "lodash": "^4.17.4" diff --git a/test/integration/runner.js b/test/integration/runner.js new file mode 100644 index 000000000..8944c618c --- /dev/null +++ b/test/integration/runner.js @@ -0,0 +1,5 @@ +require('babel-core/register')({ + ignore: /node_modules(?!\/contentful-resolve-response)/ +}) + +require('./tests.js') diff --git a/test/runner b/test/runner index 494e37a1a..6590fe9b4 100755 --- a/test/runner +++ b/test/runner @@ -1,6 +1,9 @@ #!/usr/bin/env node +require('babel-core/register')({ + ignore: /node_modules(?!\/contentful-resolve-response)/ +}) require('require-all')({ dirname: process.cwd() + '/test/unit', - filter: process.argv[2] || /\-test\.js$/, + filter: process.argv[2] || /-test\.js$/, recursive: true }) diff --git a/test/unit/contentful-test.js b/test/unit/contentful-test.js index ec2db032d..b7591fabb 100644 --- a/test/unit/contentful-test.js +++ b/test/unit/contentful-test.js @@ -79,8 +79,8 @@ test('Initializes API with link resolution turned on by default', (t) => { const apiStub = sinon.stub().returns({}) createClientRewireApi.__Rewire__('createContentfulApi', apiStub) createClient({accessToken: 'accesstoken', space: 'spaceid'}) - t.ok(apiStub.args[0][0].shouldLinksResolve({}), 'not overriden by query') - t.notOk(apiStub.args[0][0].shouldLinksResolve({resolveLinks: false}), 'overriden by query') + t.ok(apiStub.args[0][0].getGlobalOptions({}).resolveLinks, 'not overriden by query') + t.notOk(apiStub.args[0][0].getGlobalOptions({resolveLinks: false}).resolveLinks, 'overriden by query') createClientRewireApi.__ResetDependency__('createHttpClient') createClientRewireApi.__ResetDependency__('rateLimit') t.end() @@ -94,8 +94,8 @@ test('Initializes API with link resolution turned on explicitly', (t) => { const apiStub = sinon.stub().returns({}) createClientRewireApi.__Rewire__('createContentfulApi', apiStub) createClient({accessToken: 'accesstoken', space: 'spaceid', resolveLinks: true}) - t.ok(apiStub.args[0][0].shouldLinksResolve({}), 'not overriden by query') - t.notOk(apiStub.args[0][0].shouldLinksResolve({resolveLinks: false}), 'overriden by query') + t.ok(apiStub.args[0][0].getGlobalOptions({}).resolveLinks, 'not overriden by query') + t.notOk(apiStub.args[0][0].getGlobalOptions({resolveLinks: false}).resolveLinks, 'overriden by query') createClientRewireApi.__ResetDependency__('createHttpClient') createClientRewireApi.__ResetDependency__('rateLimit') t.end() diff --git a/test/unit/create-contentful-api-test.js b/test/unit/create-contentful-api-test.js index 4ba95f42f..21f67b53e 100644 --- a/test/unit/create-contentful-api-test.js +++ b/test/unit/create-contentful-api-test.js @@ -1,12 +1,13 @@ import test from 'blue-tape' import sinon from 'sinon' +import createGlobalOptions from '../../lib/create-global-options' import createContentfulApi, { __RewireAPI__ as createContentfulApiRewireApi } from '../../lib/create-contentful-api' import { contentTypeMock, assetMock, entryMock } from './mocks' let entitiesMock -function setupWithData ({promise, shouldLinksResolve = sinon.stub().returns(true)}) { +function setupWithData ({promise, getGlobalOptions = sinon.stub().returns({resolveLinks: true, removeUnresolved: false})}) { entitiesMock = { space: { wrapSpace: sinon.stub() @@ -30,7 +31,7 @@ function setupWithData ({promise, shouldLinksResolve = sinon.stub().returns(true http: { get: getStub.returns(promise) }, - shouldLinksResolve: shouldLinksResolve + getGlobalOptions: getGlobalOptions }) return {api, getStub} } @@ -220,6 +221,24 @@ test('API call getEntries', (t) => { }) }) +test('API call getEntries with global resolve links overriden by query', (t) => { + t.plan(1) + + const data = {sys: {id: 'id'}} + + const {api} = setupWithData({ + promise: Promise.resolve({ data: data }), + getGlobalOptions: createGlobalOptions({}) + }) + entitiesMock.entry.wrapEntryCollection.returns(data) + + return api.getEntries({resolveLinks: true}) + .then((r) => { + t.ok(entitiesMock.entry.wrapEntryCollection.args[0][1].resolveLinks, 'resolveLinks turned off globally') + teardown() + }) +}) + test('API call getEntries with global resolve links turned off', (t) => { t.plan(2) @@ -227,13 +246,13 @@ test('API call getEntries with global resolve links turned off', (t) => { const {api} = setupWithData({ promise: Promise.resolve({ data: data }), - shouldLinksResolve: sinon.stub().returns(false) + getGlobalOptions: sinon.stub().returns({resolveLinks: false}) }) entitiesMock.entry.wrapEntryCollection.returns(data) return api.getEntries() .then((r) => { - t.notOk(entitiesMock.entry.wrapEntryCollection.args[0][1], 'resolveLinks turned off globally') + t.notOk(entitiesMock.entry.wrapEntryCollection.args[0][1].resolveLinks, 'resolveLinks turned off globally') t.looseEqual(r, data, 'returns expected data') teardown() }) @@ -379,7 +398,7 @@ test('CDA call sync fails', (t) => { test('Given json should be parsed correctly as a collection of entries', (t) => { const api = createContentfulApi({ http: {}, - shouldLinksResolve: true + getGlobalOptions: sinon.stub().returns({resolveLinks: true}) }) const data = {items: [ { diff --git a/test/unit/entities/entry-test.js b/test/unit/entities/entry-test.js index f00430bd5..2e92798e2 100644 --- a/test/unit/entities/entry-test.js +++ b/test/unit/entities/entry-test.js @@ -87,7 +87,7 @@ test('Entry collection links are resolved', (t) => { } } - const wrappedCollection = wrapEntryCollection(entryCollection, true) + const wrappedCollection = wrapEntryCollection(entryCollection, {resolveLinks: true}) const wrappedEntry = wrappedCollection.toPlainObject() // first linked entry resolved from includes diff --git a/test/unit/mixins/link-getters-test.js b/test/unit/mixins/link-getters-test.js deleted file mode 100644 index 492fc3325..000000000 --- a/test/unit/mixins/link-getters-test.js +++ /dev/null @@ -1,143 +0,0 @@ -import test from 'blue-tape' -import mixinLinkGetters from '../../../lib/mixins/link-getters' - -test('links in response, without matching include should remain', (t) => { - const items = [{ - sys: {type: 'Entry', locale: 'en-US'}, - fields: { - animal: {sys: {type: 'Link', linkType: 'Piglet', id: 'oink'}} - } - }] - mixinLinkGetters(items, {}) - t.equal(items[0].fields.animal.sys.type, 'Link') - t.end() -}) - -test('links in response, with matching include should resolve', (t) => { - const items = [ - { - sys: {type: 'Entry', locale: 'en-US'}, - fields: { - animal: {sys: {type: 'Link', linkType: 'Animal', id: 'oink'}}, - anotheranimal: {sys: {type: 'Link', linkType: 'Animal', id: 'middle-parrot'}} - } - }, - { - sys: {type: 'Entry', locale: 'en-US'}, - fields: { - birds: [ - {sys: {type: 'Link', linkType: 'Animal', id: 'parrot'}}, - {sys: {type: 'Link', linkType: 'Animal', id: 'middle-parrot'}}, - {sys: {type: 'Link', linkType: 'Animal', id: 'aussie-parrot'}} - ] - } - }, - { - sys: {type: 'Entry'}, - fields: { - animal: { - 'en-US': {sys: {type: 'Link', linkType: 'Animal', id: 'oink'}} - }, - animals: { - 'en-US': [{sys: {type: 'Link', linkType: 'Animal', id: 'oink'}}] - } - } - } - ] - const includes = { - Animal: [ - { - sys: {type: 'Animal', id: 'oink', locale: 'en-US'}, - fields: { - name: 'Pig', - friend: {sys: {type: 'Link', linkType: 'Animal', id: 'groundhog'}} - } - }, - { - sys: {type: 'Animal', id: 'groundhog', locale: 'en-US'}, - fields: {name: 'Phil'} - }, - { - sys: {type: 'Animal', id: 'parrot', locale: 'en-US'}, - fields: {name: 'Parrot'} - }, - { - sys: {type: 'Animal', id: 'aussie-parrot', locale: 'en-US'}, - fields: {name: 'Aussie Parrot'} - } - ] - } - - mixinLinkGetters(items, includes) - t.looseEquals(items[0].fields.animal.sys, includes.Animal[0].sys, 'pig') - t.looseEquals(items[0].fields.animal.fields.friend.sys, includes.Animal[1].sys, 'groundhog') - t.looseEquals(items[0].fields.anotheranimal.sys.type, 'Link', 'first middle parrot not resolved') - t.looseEquals(items[1].fields.birds[0], includes.Animal[2], 'parrot') - t.looseEquals(items[1].fields.birds[1].sys.type, 'Link', 'second middle parrot not resolved') - t.looseEquals(items[1].fields.birds[2], includes.Animal[3], 'aussie parrot') - t.looseEquals(items[2].fields.animal['en-US'].sys, includes.Animal[0].sys, 'localized pig') - t.looseEquals(items[2].fields.animal['en-US'].fields.friend.sys, includes.Animal[1].sys, 'localized groundhog') - t.looseEquals(items[2].fields.animals['en-US'][0].sys, includes.Animal[0].sys, 'listed localized pig') - t.looseEquals(items[2].fields.animals['en-US'][0].fields.friend.sys, includes.Animal[1].sys, 'listed localized groundhog') - t.end() -}) - -test('links in response, with circular references', (t) => { - const items = [ - { - sys: {type: 'Entry', locale: 'en-US'}, - fields: { - animal: {sys: {type: 'Link', linkType: 'Animal', id: 'oink'}} - } - } - ] - const includes = { - Animal: [ - { - sys: {type: 'Animal', id: 'oink', locale: 'en-US'}, - fields: {name: 'Pig', friend: {sys: {type: 'Link', linkType: 'Animal', id: 'parrot'}}} - }, - { - sys: {type: 'Animal', id: 'parrot', locale: 'en-US'}, - fields: {name: 'Parrot', friend: {sys: {type: 'Link', linkType: 'Animal', id: 'oink'}}} - } - ] - } - - mixinLinkGetters(items, includes) - - t.equals(items[0].fields.animal.sys.type, 'Animal', 'first link type') - t.equals(items[0].fields.animal.sys.id, 'oink', 'first link id') - t.equals(items[0].fields.animal.fields.friend.sys.type, 'Animal', 'sub link type') - t.equals(items[0].fields.animal.fields.friend.sys.id, 'parrot', 'sub link id') - t.equals(items[0].fields.animal.fields.friend.fields.friend.sys.type, 'Animal', 'sub sub link type') - t.equals(items[0].fields.animal.fields.friend.fields.friend.sys.id, 'oink', 'sub sub link id') - t.end() -}) - -test('links in response with locale: *', (t) => { - const items = [ - { - sys: {type: 'Entry'}, - fields: { - animal: { 'en': {sys: {type: 'Link', linkType: 'Entry', id: 'oink'}} }, - animals: { 'en': [{sys: {type: 'Link', linkType: 'Entry', id: 'oink'}}] } - } - } - ] - const includes = { - Entry: [ - { - sys: {type: 'Entry', id: 'oink'}, - fields: { - name: { - 'en': 'Pig' - } - } - } - ] - } - mixinLinkGetters(items, includes) - t.equals(items[0].fields.animal['en'].fields.name['en'], includes.Entry[0].fields.name['en']) - t.end() -}) diff --git a/test/unit/paged-sync-test.js b/test/unit/paged-sync-test.js index 9d20e047a..b4928c3a2 100644 --- a/test/unit/paged-sync-test.js +++ b/test/unit/paged-sync-test.js @@ -71,7 +71,7 @@ test('Initial sync with one page', (t) => { } })) - return pagedSync(http, {initial: true}, true) + return pagedSync(http, {initial: true}, {resolveLinks: true}) .then((response) => { t.ok(http.get.args[0][1].params.initial, 'http request has initial param') t.equal(response.entries.length, 3, 'entries length') @@ -101,7 +101,7 @@ test('Initial sync with one page and filter', (t) => { } })) - return pagedSync(http, {initial: true, content_type: 'cat'}, true) + return pagedSync(http, {initial: true, content_type: 'cat'}, {resolveLinks: true}) .then((response) => { t.ok(http.get.args[0][1].params.initial, 'http request has initial param') t.equal(http.get.args[0][1].params.content_type, 'cat', 'http request has content type filter param') diff --git a/webpack.config.js b/webpack.config.js index 9ae7852b1..31b594438 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -56,10 +56,7 @@ const baseBundleConfig = { const defaultBabelLoader = { test: /\.js?$/, - include: [ - path.resolve(__dirname, 'lib'), - path.resolve(__dirname, 'test') - ], + exclude: /node_modules(?!\/contentful-resolve-response)/, loader: 'babel-loader', options: {} }