Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(gatsby-source-contentful): use reporter progressbar instead of own #29853

Merged
merged 2 commits into from
Mar 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion packages/gatsby-source-contentful/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
"lodash": "^4.17.20",
"node-fetch": "^2.6.1",
"p-queue": "^6.6.2",
"progress": "^2.0.3",
"qs": "^6.9.6",
"retry-axios": "^2.4.0"
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,5 @@
const { downloadContentfulAssets } = require(`../download-contentful-assets`)

jest.mock(
`progress`,
() =>
class MockProgress {
constructor() {
this.tick = jest.fn()
}
}
)

jest.mock(`gatsby-source-filesystem`, () => {
return {
createRemoteFileNode: jest.fn(({ url }) => {
Expand All @@ -20,6 +10,15 @@ jest.mock(`gatsby-source-filesystem`, () => {
}
})

const reporter = {
createProgress: jest.fn(() => {
return {
start: jest.fn(),
tick: jest.fn(),
}
}),
}

const fixtures = [
{
id: `aa1beda4-b14a-50f5-89a8-222992a46a41`,
Expand Down Expand Up @@ -66,6 +65,7 @@ describe.only(`downloadContentfulAssets`, () => {
getNodesByType: () => fixtures,
cache,
assetDownloadWorkers: 50,
reporter,
})

fixtures.forEach(n => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,5 @@
const ProgressBar = require(`progress`)
const { createRemoteFileNode } = require(`gatsby-source-filesystem`)

const bar = new ProgressBar(
`Downloading Contentful Assets [:bar] :current/:total :elapsed secs :percent`,
{
total: 0,
width: 30,
}
)

/**
* @name distributeWorkload
* @param workers A list of async functions to complete
Expand Down Expand Up @@ -51,15 +42,19 @@ const downloadContentfulAssets = async gatsbyFunctions => {
// regardless of if you use `localFile` to link an asset or not.

const assetNodes = getNodesByType(`ContentfulAsset`)
bar.total = assetNodes.length

const bar = reporter.createProgress(
`Downloading Contentful Assets`,
assetNodes.length
)
bar.start()
await distributeWorkload(
assetNodes.map(node => async () => {
let fileNodeID
const { contentful_id: id, node_locale: locale } = node
const remoteDataCacheKey = `contentful-asset-${id}-${locale}`
const cacheRemoteData = await cache.get(remoteDataCacheKey)
if (!node.file) {
reporter.log(id, locale)
reporter.warn(`The asset with id: ${id}, contains no file.`)
return Promise.resolve()
}
Expand Down