Skip to content

Commit

Permalink
remove progressbar (#29452)
Browse files Browse the repository at this point in the history
  • Loading branch information
LB committed Feb 12, 2021
1 parent 9428145 commit f3a5b0d
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 112 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,32 +22,17 @@ jest.mock(`got`, () => {
}
})

jest.mock(`gatsby-cli/lib/reporter`, () => {
return {
createProgress: jest.fn(),
}
})
jest.mock(`../create-file-node`, () => {
return {
createFileNode: jest.fn(),
}
})
const reporter = require(`gatsby-cli/lib/reporter`)
const progressBar = {
start: jest.fn(),
total: 0,
tick: jest.fn(),
}
reporter.createProgress.mockImplementation(() => progressBar)

const got = require(`got`)
const createRemoteFileNode = require(`../create-remote-file-node`)
const { createFileNode } = require(`../create-file-node`)

beforeEach(() => {
progressBar.tick.mockClear()
})

const createMockCache = () => {
return {
get: jest.fn(),
Expand Down Expand Up @@ -90,9 +75,6 @@ describe(`create-remote-file-node`, () => {
expect(value).rejects.toMatch(
`url passed to createRemoteFileNode is either missing or not a proper web uri: `
)

expect(progressBar.total).toBe(0)
expect(progressBar.tick).not.toHaveBeenCalled()
})
})
})
Expand Down Expand Up @@ -157,9 +139,6 @@ describe(`create-remote-file-node`, () => {

it(`invokes ProgressBar tick`, async () => {
await setup()

expect(progressBar.total).toBe(1)
expect(progressBar.tick).toHaveBeenCalledTimes(1)
})

describe(`requesting remote image`, () => {
Expand Down
39 changes: 1 addition & 38 deletions packages/gatsby-source-filesystem/src/__tests__/utils.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
jest.mock(`gatsby-cli/lib/reporter`)
jest.mock(`progress`)
const {
getRemoteFileExtension,
getRemoteFileName,
createProgress,
} = require(`../utils`)
const reporter = require(`gatsby-cli/lib/reporter`)
const progress = require(`progress`)
const { getRemoteFileExtension, getRemoteFileName } = require(`../utils`)

describe(`create remote file node`, () => {
it(`can correctly retrieve file name and extensions`, () => {
Expand All @@ -30,34 +24,3 @@ describe(`create remote file node`, () => {
})
})
})

describe(`createProgress`, () => {
beforeEach(() => {
progress.mockClear()
})

it(`should use createProgress from gatsby-cli when available`, () => {
createProgress(`test`, reporter)
expect(reporter.createProgress).toBeCalled()
expect(progress).not.toBeCalled()
})

it(`should fallback to a local implementation when createProgress does not exists on reporter`, () => {
reporter.createProgress = null
const bar = createProgress(`test`, reporter)
expect(progress).toHaveBeenCalledTimes(1)
expect(bar).toHaveProperty(`start`, expect.any(Function))
expect(bar).toHaveProperty(`tick`, expect.any(Function))
expect(bar).toHaveProperty(`done`, expect.any(Function))
expect(bar).toHaveProperty(`total`)
})

it(`should fallback to a local implementation when no reporter is present`, () => {
const bar = createProgress(`test`)
expect(progress).toHaveBeenCalledTimes(1)
expect(bar).toHaveProperty(`start`, expect.any(Function))
expect(bar).toHaveProperty(`tick`, expect.any(Function))
expect(bar).toHaveProperty(`done`, expect.any(Function))
expect(bar).toHaveProperty(`total`)
})
})
27 changes: 1 addition & 26 deletions packages/gatsby-source-filesystem/src/create-remote-file-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ const path = require(`path`)
const { isWebUri } = require(`valid-url`)
const Queue = require(`better-queue`)
const fileType = require(`file-type`)
const { createProgress } = require(`./utils`)

const { createFileNode } = require(`./create-file-node`)
const {
Expand All @@ -16,10 +15,6 @@ const {
const cacheIdForHeaders = url => `create-remote-file-node-headers-${url}`
const cacheIdForExtensions = url => `create-remote-file-node-extension-${url}`

let bar
// Keep track of the total number of jobs we push in the queue
let totalJobs = 0

let showFlagWarning = !!process.env.GATSBY_EXPERIMENTAL_REMOTE_FILE_PLACEHOLDER

/********************
Expand Down Expand Up @@ -79,14 +74,6 @@ const queue = new Queue(pushToQueue, {
concurrent: process.env.GATSBY_CONCURRENT_DOWNLOAD || 200,
})

// when the queue is empty we stop the progressbar
queue.on(`drain`, () => {
if (bar) {
bar.done()
}
totalJobs = 0
})

/**
* @callback {Queue~queueCallback}
* @param {*} error
Expand Down Expand Up @@ -458,14 +445,6 @@ module.exports = function createRemoteFileNode({
)
}

if (totalJobs === 0) {
bar = createProgress(`Downloading remote files`, reporter)
bar.start()
}

totalJobs += 1
bar.total = totalJobs

const fileDownloadPromise = pushTask({
url,
cache,
Expand All @@ -478,11 +457,7 @@ module.exports = function createRemoteFileNode({
name,
})

processingCache[url] = fileDownloadPromise.then(node => {
bar.tick()

return node
})
processingCache[url] = fileDownloadPromise.then(node => node)

return processingCache[url]
}
27 changes: 0 additions & 27 deletions packages/gatsby-source-filesystem/src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,33 +41,6 @@ export function getRemoteFileName(url) {
return getParsedPath(url).name
}

// TODO remove in V3
export function createProgress(message, reporter) {
if (reporter && reporter.createProgress) {
return reporter.createProgress(message)
}

const bar = new ProgressBar(
` [:bar] :current/:total :elapsed s :percent ${message}`,
{
total: 0,
width: 30,
clear: true,
}
)

return {
start() {},
tick() {
bar.tick()
},
done() {},
set total(value) {
bar.total = value
},
}
}

/**
* createFilePath
* --
Expand Down

0 comments on commit f3a5b0d

Please sign in to comment.