diff --git a/packages/gatsby-plugin-manifest/src/gatsby-node.js b/packages/gatsby-plugin-manifest/src/gatsby-node.js index 01378dc81b5d1..ff888fb5fb9ca 100644 --- a/packages/gatsby-plugin-manifest/src/gatsby-node.js +++ b/packages/gatsby-plugin-manifest/src/gatsby-node.js @@ -57,8 +57,13 @@ async function checkCache(cache, icon, srcIcon, srcIconDigest, callback) { } } -exports.onPostBootstrap = async ({ reporter }, { localize, ...manifest }) => { - const activity = reporter.activityTimer(`Build manifest and related icons`) +exports.onPostBootstrap = async ( + { reporter, parentSpan }, + { localize, ...manifest } +) => { + const activity = reporter.activityTimer(`Build manifest and related icons`, { + parentSpan, + }) activity.start() let cache = new Map() diff --git a/packages/gatsby-plugin-sharp/src/__tests__/index.js b/packages/gatsby-plugin-sharp/src/__tests__/index.js index cb93f92cf4368..9d606800a6480 100644 --- a/packages/gatsby-plugin-sharp/src/__tests__/index.js +++ b/packages/gatsby-plugin-sharp/src/__tests__/index.js @@ -21,6 +21,22 @@ const { const { scheduleJob } = require(`../scheduler`) scheduleJob.mockResolvedValue(Promise.resolve()) +jest.mock(`gatsby-cli/lib/reporter`, () => { + return { + log: jest.fn(), + info: jest.fn(), + warn: jest.fn(), + error: jest.fn(), + activityTimer: () => { + return { + start: jest.fn(), + setStatus: jest.fn(), + end: jest.fn(), + } + }, + } +}) + describe(`gatsby-plugin-sharp`, () => { const args = { duotone: false, diff --git a/packages/gatsby-transformer-remark/src/__tests__/extend-node.js b/packages/gatsby-transformer-remark/src/__tests__/extend-node.js index 6c9a8503f0253..d3faa8436de4a 100644 --- a/packages/gatsby-transformer-remark/src/__tests__/extend-node.js +++ b/packages/gatsby-transformer-remark/src/__tests__/extend-node.js @@ -4,6 +4,22 @@ const extendNodeType = require(`../extend-node-type`) const { createContentDigest } = require(`gatsby-core-utils`) const { typeDefs } = require(`../create-schema-customization`) +jest.mock(`gatsby-cli/lib/reporter`, () => { + return { + log: jest.fn(), + info: jest.fn(), + warn: jest.fn(), + error: jest.fn(), + activityTimer: () => { + return { + start: jest.fn(), + setStatus: jest.fn(), + end: jest.fn(), + } + }, + } +}) + // given a set of nodes and a query, return the result of the query async function queryResult( nodes, diff --git a/packages/gatsby/src/bootstrap/index.js b/packages/gatsby/src/bootstrap/index.js index d9c5398b403c1..fd71eb0773578 100644 --- a/packages/gatsby/src/bootstrap/index.js +++ b/packages/gatsby/src/bootstrap/index.js @@ -117,7 +117,7 @@ module.exports = async (args: BootstrapArgs) => { const apis = await getLatestAPIs() - activity = report.activityTimer(`load plugins`) + activity = report.activityTimer(`load plugins`, { parentSpan: bootstrapSpan }) activity.start() const flattenedPlugins = await loadPlugins(config, program.directory, apis) activity.end() @@ -153,7 +153,9 @@ module.exports = async (args: BootstrapArgs) => { activity.end() } - activity = report.activityTimer(`initialize cache`) + activity = report.activityTimer(`initialize cache`, { + parentSpan: bootstrapSpan, + }) activity.start() // Check if any plugins have been updated since our last run. If so // we delete the cache is there's likely been changes @@ -365,9 +367,13 @@ module.exports = async (args: BootstrapArgs) => { */ // onPreBootstrap - activity = report.activityTimer(`onPreBootstrap`) + activity = report.activityTimer(`onPreBootstrap`, { + parentSpan: bootstrapSpan, + }) activity.start() - await apiRunnerNode(`onPreBootstrap`) + await apiRunnerNode(`onPreBootstrap`, { + parentSpan: activity.span, + }) activity.end() // Source nodes @@ -451,7 +457,7 @@ module.exports = async (args: BootstrapArgs) => { parentSpan: bootstrapSpan, }) activity.start() - await extractQueries() + await extractQueries({ parentSpan: activity.span }) activity.end() // Write out files. diff --git a/packages/gatsby/src/commands/build-html.js b/packages/gatsby/src/commands/build-html.js index 7fd88b59dcfff..e187f9f60be06 100644 --- a/packages/gatsby/src/commands/build-html.js +++ b/packages/gatsby/src/commands/build-html.js @@ -33,9 +33,11 @@ const doBuildRenderer = async (program, webpackConfig) => { return outputFile } -const buildRenderer = async (program, stage) => { +const buildRenderer = async (program, stage, { parentSpan }) => { const { directory } = program - const config = await webpackConfig(program, directory, stage, null) + const config = await webpackConfig(program, directory, stage, null, { + parentSpan, + }) return await doBuildRenderer(program, config) } @@ -120,7 +122,9 @@ const buildPages = async ({ activity, workerPool, }) => { - const rendererPath = await buildRenderer(program, stage) + const rendererPath = await buildRenderer(program, stage, { + parentSpan: activity.span, + }) await doBuildPages({ rendererPath, pagePaths, activity, workerPool }) await deleteRenderer(rendererPath) } diff --git a/packages/gatsby/src/commands/build-javascript.js b/packages/gatsby/src/commands/build-javascript.js index ae20f5d58b60d..791ae98e81277 100644 --- a/packages/gatsby/src/commands/build-javascript.js +++ b/packages/gatsby/src/commands/build-javascript.js @@ -2,13 +2,15 @@ const webpack = require(`webpack`) const webpackConfig = require(`../utils/webpack.config`) -module.exports = async program => { +module.exports = async (program, { parentSpan }) => { const { directory } = program const compilerConfig = await webpackConfig( program, directory, - `build-javascript` + `build-javascript`, + null, + { parentSpan } ) return new Promise((resolve, reject) => { diff --git a/packages/gatsby/src/commands/build.js b/packages/gatsby/src/commands/build.js index adc5ad88199a0..fe7a73e1a8013 100644 --- a/packages/gatsby/src/commands/build.js +++ b/packages/gatsby/src/commands/build.js @@ -83,7 +83,9 @@ module.exports = async function build(program: BuildArgs) { { parentSpan: buildSpan } ) activity.start() - const stats = await buildProductionBundle(program).catch(err => { + const stats = await buildProductionBundle(program, { + parentSpan: activity.span, + }).catch(err => { report.panic(handleWebpackError(`build-javascript`, err)) }) activity.end() @@ -119,7 +121,9 @@ module.exports = async function build(program: BuildArgs) { activity.end() } - activity = report.activityTimer(`run page queries`) + activity = report.activityTimer(`run page queries`, { + parentSpan: buildSpan, + }) activity.start() await queryUtil.processPageQueries(pageQueryIds, { activity }) activity.end() diff --git a/packages/gatsby/src/commands/develop.js b/packages/gatsby/src/commands/develop.js index a097e7f218ee1..687dc49a0e814 100644 --- a/packages/gatsby/src/commands/develop.js +++ b/packages/gatsby/src/commands/develop.js @@ -79,17 +79,18 @@ const waitJobsFinished = () => onEndJob() }) -async function startServer(program) { +async function startServer(program, { activity }) { const directory = program.directory const directoryPath = withBasePath(directory) const workerPool = WorkerPool.create() - const createIndexHtml = async () => { + const createIndexHtml = async ({ activity }) => { try { await buildHTML.buildPages({ program, stage: `develop-html`, pagePaths: [`/`], workerPool, + activity, }) } catch (err) { if (err.name !== `WebpackError`) { @@ -107,13 +108,14 @@ async function startServer(program) { } } - await createIndexHtml() + await createIndexHtml({ activity }) const devConfig = await webpackConfig( program, directory, `develop`, - program.port + program.port, + { parentSpan: activity.span } ) const compiler = webpack(devConfig) @@ -375,7 +377,10 @@ module.exports = async (program: any) => { queryUtil.startListening(queryQueue.createDevelopQueue()) queryWatcher.startWatchDeletePage() - const [compiler] = await startServer(program) + activity = report.activityTimer(`start webpack server`) + activity.start() + const [compiler] = await startServer(program, { activity }) + activity.end() function prepareUrls(protocol, host, port) { const formatUrl = hostname => diff --git a/packages/gatsby/src/internal-plugins/load-babel-config/gatsby-node.js b/packages/gatsby/src/internal-plugins/load-babel-config/gatsby-node.js index 5f0cf62307ef6..6c95b82e82f12 100644 --- a/packages/gatsby/src/internal-plugins/load-babel-config/gatsby-node.js +++ b/packages/gatsby/src/internal-plugins/load-babel-config/gatsby-node.js @@ -5,21 +5,25 @@ const fs = require(`fs-extra`) const apiRunnerNode = require(`../../utils/api-runner-node`) const { withBasePath } = require(`../../utils/path`) -exports.onPreBootstrap = async ({ store }) => { +exports.onPreBootstrap = async ({ store, parentSpan }) => { const { directory, browserslist } = store.getState().program const directoryPath = withBasePath(directory) await apiRunnerNode(`onCreateBabelConfig`, { stage: `develop`, + parentSpan, }) await apiRunnerNode(`onCreateBabelConfig`, { stage: `develop-html`, + parentSpan, }) await apiRunnerNode(`onCreateBabelConfig`, { stage: `build-javascript`, + parentSpan, }) await apiRunnerNode(`onCreateBabelConfig`, { stage: `build-html`, + parentSpan, }) const babelState = JSON.stringify( diff --git a/packages/gatsby/src/query/file-parser.js b/packages/gatsby/src/query/file-parser.js index 5f5d1b854e645..b61233d21d52c 100644 --- a/packages/gatsby/src/query/file-parser.js +++ b/packages/gatsby/src/query/file-parser.js @@ -37,7 +37,7 @@ Perhaps the variable name has a typo? Also note that we are currently unable to use queries defined in files other than the file where the ${usageFunction} is defined. If you're attempting to import the query, please move it into "${file}". If being able to import queries from another file is an important capability for you, we invite your help fixing it.\n` ) -async function parseToAst(filePath, fileStr) { +async function parseToAst(filePath, fileStr, { parentSpan } = {}) { let ast // Preprocess and attempt to parse source; return an AST if we can, log an @@ -45,6 +45,7 @@ async function parseToAst(filePath, fileStr) { const transpiled = await apiRunnerNode(`preprocessSource`, { filename: filePath, contents: fileStr, + parentSpan: parentSpan, }) if (transpiled && transpiled.length) { for (const item of transpiled) { @@ -97,9 +98,13 @@ const warnForGlobalTag = file => file ) -async function findGraphQLTags(file, text): Promise> { +async function findGraphQLTags( + file, + text, + { parentSpan } = {} +): Promise> { return new Promise((resolve, reject) => { - parseToAst(file, text) + parseToAst(file, text, { parentSpan }) .then(ast => { let queries = [] if (!ast) { @@ -318,6 +323,10 @@ async function findGraphQLTags(file, text): Promise> { const cache = {} export default class FileParser { + constructor({ parentSpan } = {}) { + this.parentSpan = parentSpan + } + async parseFile(file: string): Promise { let text try { @@ -339,7 +348,10 @@ export default class FileParser { try { let astDefinitions = - cache[hash] || (cache[hash] = await findGraphQLTags(file, text)) + cache[hash] || + (cache[hash] = await findGraphQLTags(file, text, { + parentSpan: this.parentSpan, + })) // If any AST definitions were extracted, report success. // This can mean there is none or there was a babel error when diff --git a/packages/gatsby/src/query/query-compiler.js b/packages/gatsby/src/query/query-compiler.js index 0b51c447f1da8..302d2c393de1a 100644 --- a/packages/gatsby/src/query/query-compiler.js +++ b/packages/gatsby/src/query/query-compiler.js @@ -81,10 +81,16 @@ class Runner { errors: string[] fragmentsDir: string - constructor(base: string, additional: string[], schema: GraphQLSchema) { + constructor( + base: string, + additional: string[], + schema: GraphQLSchema, + { parentSpan } = {} + ) { this.base = base this.additional = additional this.schema = schema + this.parentSpan = parentSpan } reportError(message) { @@ -146,7 +152,7 @@ class Runner { files = _.uniq(files) - let parser = new FileParser() + let parser = new FileParser({ parentSpan: this.parentSpan }) return await parser.parseFiles(files) } @@ -364,7 +370,9 @@ class Runner { } export { Runner, resolveThemes } -export default async function compile(): Promise> { +export default async function compile({ parentSpan } = {}): Promise< + Map +> { // TODO: swap plugins to themes const { program, schema, themes, flattenedPlugins } = store.getState() @@ -379,7 +387,8 @@ export default async function compile(): Promise> { } }) ), - schema + schema, + { parentSpan } ) const queries = await runner.compileAll() diff --git a/packages/gatsby/src/query/query-watcher.js b/packages/gatsby/src/query/query-watcher.js index 96094c8c70be5..8dce7707081f0 100644 --- a/packages/gatsby/src/query/query-watcher.js +++ b/packages/gatsby/src/query/query-watcher.js @@ -95,9 +95,9 @@ const handleQuery = ( return false } -const updateStateAndRunQueries = isFirstRun => { +const updateStateAndRunQueries = (isFirstRun, { parentSpan } = {}) => { const snapshot = getQueriesSnapshot() - return queryCompiler().then(queries => { + return queryCompiler({ parentSpan }).then(queries => { // If there's an error while extracting queries, the queryCompiler returns false // or zero results. // Yeah, should probably be an error but don't feel like threading the error @@ -184,14 +184,14 @@ const clearInactiveComponents = () => { }) } -exports.extractQueries = () => { +exports.extractQueries = ({ parentSpan } = {}) => { // Remove template components that point to not existing page templates. // We need to do this, because components data is cached and there might // be changes applied when development server isn't running. This is needed // only in initial run, because during development state will be adjusted. clearInactiveComponents() - return updateStateAndRunQueries(true).then(() => { + return updateStateAndRunQueries(true, { parentSpan }).then(() => { // During development start watching files to recompile & run // queries on the fly. if (process.env.NODE_ENV !== `production`) { diff --git a/packages/gatsby/src/schema/__tests__/build-node-connections.js b/packages/gatsby/src/schema/__tests__/build-node-connections.js index 762bb5a18dbd8..ebd12002120a9 100644 --- a/packages/gatsby/src/schema/__tests__/build-node-connections.js +++ b/packages/gatsby/src/schema/__tests__/build-node-connections.js @@ -10,6 +10,22 @@ const createPageDependency = require(`../../redux/actions/add-page-dependency`) require(`../../db/__tests__/fixtures/ensure-loki`)() +jest.mock(`gatsby-cli/lib/reporter`, () => { + return { + log: jest.fn(), + info: jest.fn(), + warn: jest.fn(), + error: jest.fn(), + activityTimer: () => { + return { + start: jest.fn(), + setStatus: jest.fn(), + end: jest.fn(), + } + }, + } +}) + const makeNodes = () => [ { id: `p1`, diff --git a/packages/gatsby/src/schema/__tests__/build-node-types.js b/packages/gatsby/src/schema/__tests__/build-node-types.js index 05071b4a38cf6..55c4ae0d95a07 100644 --- a/packages/gatsby/src/schema/__tests__/build-node-types.js +++ b/packages/gatsby/src/schema/__tests__/build-node-types.js @@ -17,6 +17,22 @@ const { TypeConflictReporter } = require(`../infer/type-conflict-reporter`) const typeConflictReporter = new TypeConflictReporter() const addConflictSpy = jest.spyOn(typeConflictReporter, `addConflict`) +jest.mock(`gatsby-cli/lib/reporter`, () => { + return { + log: jest.fn(), + info: jest.fn(), + warn: jest.fn(), + error: jest.fn(), + activityTimer: () => { + return { + start: jest.fn(), + setStatus: jest.fn(), + end: jest.fn(), + } + }, + } +}) + const makeNodes = () => [ { id: `p1`, diff --git a/packages/gatsby/src/schema/__tests__/build-schema.js b/packages/gatsby/src/schema/__tests__/build-schema.js index efeaf9d5b6824..7de69961f2c75 100644 --- a/packages/gatsby/src/schema/__tests__/build-schema.js +++ b/packages/gatsby/src/schema/__tests__/build-schema.js @@ -20,7 +20,22 @@ require(`../../db/__tests__/fixtures/ensure-loki`)() const nodes = require(`./fixtures/node-model`) -jest.mock(`gatsby-cli/lib/reporter`) +jest.mock(`gatsby-cli/lib/reporter`, () => { + return { + log: jest.fn(), + info: jest.fn(), + warn: jest.fn(), + error: jest.fn(), + activityTimer: () => { + return { + start: jest.fn(), + setStatus: jest.fn(), + end: jest.fn(), + } + }, + } +}) + const report = require(`gatsby-cli/lib/reporter`) afterEach(() => report.warn.mockClear()) diff --git a/packages/gatsby/src/schema/__tests__/context.js b/packages/gatsby/src/schema/__tests__/context.js index 36a2d9a69b3f3..0aa1fca8df458 100644 --- a/packages/gatsby/src/schema/__tests__/context.js +++ b/packages/gatsby/src/schema/__tests__/context.js @@ -8,7 +8,21 @@ const { actions } = require(`../../redux/actions/restricted`) const { createTypes, createFieldExtension, createResolverContext } = actions require(`../../db/__tests__/fixtures/ensure-loki`)() -jest.mock(`gatsby-cli/lib/reporter`) +jest.mock(`gatsby-cli/lib/reporter`, () => { + return { + log: jest.fn(), + info: jest.fn(), + warn: jest.fn(), + error: jest.fn(), + activityTimer: () => { + return { + start: jest.fn(), + setStatus: jest.fn(), + end: jest.fn(), + } + }, + } +}) const report = require(`gatsby-cli/lib/reporter`) afterEach(() => { report.error.mockClear() diff --git a/packages/gatsby/src/schema/__tests__/kitchen-sink.js b/packages/gatsby/src/schema/__tests__/kitchen-sink.js index d0c7d9e0dc24a..42a1e7f0a8950 100644 --- a/packages/gatsby/src/schema/__tests__/kitchen-sink.js +++ b/packages/gatsby/src/schema/__tests__/kitchen-sink.js @@ -20,6 +20,22 @@ require(`../../db/__tests__/fixtures/ensure-loki`)() jest.mock(`../../utils/api-runner-node`) const apiRunnerNode = require(`../../utils/api-runner-node`) +jest.mock(`gatsby-cli/lib/reporter`, () => { + return { + log: jest.fn(), + info: jest.fn(), + warn: jest.fn(), + error: jest.fn(), + activityTimer: () => { + return { + start: jest.fn(), + setStatus: jest.fn(), + end: jest.fn(), + } + }, + } +}) + // XXX(freiksenet): Expand describe(`Kitchen sink schema test`, () => { let schema diff --git a/packages/gatsby/src/schema/__tests__/print.js b/packages/gatsby/src/schema/__tests__/print.js index 95cce31edf16a..ad425ae107f11 100644 --- a/packages/gatsby/src/schema/__tests__/print.js +++ b/packages/gatsby/src/schema/__tests__/print.js @@ -11,7 +11,21 @@ afterEach(() => { fs.writeFile.mockClear() }) -jest.mock(`gatsby-cli/lib/reporter`) +jest.mock(`gatsby-cli/lib/reporter`, () => { + return { + log: jest.fn(), + info: jest.fn(), + warn: jest.fn(), + error: jest.fn(), + activityTimer: () => { + return { + start: jest.fn(), + setStatus: jest.fn(), + end: jest.fn(), + } + }, + } +}) const report = require(`gatsby-cli/lib/reporter`) afterEach(() => { report.error.mockClear() diff --git a/packages/gatsby/src/schema/__tests__/queries.js b/packages/gatsby/src/schema/__tests__/queries.js index db89a499965b1..86ed0ec6ed247 100644 --- a/packages/gatsby/src/schema/__tests__/queries.js +++ b/packages/gatsby/src/schema/__tests__/queries.js @@ -9,6 +9,22 @@ const apiRunnerNode = require(`../../utils/api-runner-node`) const nodes = require(`./fixtures/queries`) +jest.mock(`gatsby-cli/lib/reporter`, () => { + return { + log: jest.fn(), + info: jest.fn(), + warn: jest.fn(), + error: jest.fn(), + activityTimer: () => { + return { + start: jest.fn(), + setStatus: jest.fn(), + end: jest.fn(), + } + }, + } +}) + describe(`Query schema`, () => { let schema diff --git a/packages/gatsby/src/schema/__tests__/rebuild-schema.js b/packages/gatsby/src/schema/__tests__/rebuild-schema.js index 2d6cf947804e1..1caf01827f663 100644 --- a/packages/gatsby/src/schema/__tests__/rebuild-schema.js +++ b/packages/gatsby/src/schema/__tests__/rebuild-schema.js @@ -2,6 +2,22 @@ const { store } = require(`../../redux`) const { build, rebuildWithSitePage } = require(`..`) require(`../../db/__tests__/fixtures/ensure-loki`)() +jest.mock(`gatsby-cli/lib/reporter`, () => { + return { + log: jest.fn(), + info: jest.fn(), + warn: jest.fn(), + error: jest.fn(), + activityTimer: () => { + return { + start: jest.fn(), + setStatus: jest.fn(), + end: jest.fn(), + } + }, + } +}) + const firstPage = { id: `page1`, parent: null, diff --git a/packages/gatsby/src/schema/extensions/__tests__/child-relations.js b/packages/gatsby/src/schema/extensions/__tests__/child-relations.js index 3c3684fd3d0c9..8171c1386bac5 100644 --- a/packages/gatsby/src/schema/extensions/__tests__/child-relations.js +++ b/packages/gatsby/src/schema/extensions/__tests__/child-relations.js @@ -12,6 +12,13 @@ const report = require(`gatsby-cli/lib/reporter`) report.error = jest.fn() report.panic = jest.fn() report.warn = jest.fn() +report.activityTimer = jest.fn(() => { + return { + start: jest.fn(), + setStatus: jest.fn(), + end: jest.fn(), + } +}) afterEach(() => { report.error.mockClear() report.panic.mockClear() diff --git a/packages/gatsby/src/schema/extensions/__tests__/field-extensions.js b/packages/gatsby/src/schema/extensions/__tests__/field-extensions.js index 90728aa2dc98e..315538b27d865 100644 --- a/packages/gatsby/src/schema/extensions/__tests__/field-extensions.js +++ b/packages/gatsby/src/schema/extensions/__tests__/field-extensions.js @@ -12,6 +12,13 @@ require(`../../../db/__tests__/fixtures/ensure-loki`)() const report = require(`gatsby-cli/lib/reporter`) report.error = jest.fn() report.panic = jest.fn() +report.activityTimer = jest.fn(() => { + return { + start: jest.fn(), + setStatus: jest.fn(), + end: jest.fn(), + } +}) afterEach(() => { report.error.mockClear() report.panic.mockClear() diff --git a/packages/gatsby/src/schema/extensions/__tests__/interfaces.js b/packages/gatsby/src/schema/extensions/__tests__/interfaces.js index 2f2086f9614b6..96329ba6fa2e8 100644 --- a/packages/gatsby/src/schema/extensions/__tests__/interfaces.js +++ b/packages/gatsby/src/schema/extensions/__tests__/interfaces.js @@ -17,6 +17,22 @@ afterEach(() => { report.panic.mockClear() }) +jest.mock(`gatsby-cli/lib/reporter`, () => { + return { + log: jest.fn(), + info: jest.fn(), + warn: jest.fn(), + error: jest.fn(), + activityTimer: () => { + return { + start: jest.fn(), + setStatus: jest.fn(), + end: jest.fn(), + } + }, + } +}) + describe(`Queryable Node interfaces`, () => { beforeEach(() => { dispatch({ type: `DELETE_CACHE` }) diff --git a/packages/gatsby/src/schema/infer/__tests__/infer-input.js b/packages/gatsby/src/schema/infer/__tests__/infer-input.js index ed36fcee289e5..6d82c8eaf75b2 100644 --- a/packages/gatsby/src/schema/infer/__tests__/infer-input.js +++ b/packages/gatsby/src/schema/infer/__tests__/infer-input.js @@ -9,6 +9,22 @@ const { store } = require(`../../../redux`) const createPageDependency = require(`../../../redux/actions/add-page-dependency`) require(`../../../db/__tests__/fixtures/ensure-loki`)() +jest.mock(`gatsby-cli/lib/reporter`, () => { + return { + log: jest.fn(), + info: jest.fn(), + warn: jest.fn(), + error: jest.fn(), + activityTimer: () => { + return { + start: jest.fn(), + setStatus: jest.fn(), + end: jest.fn(), + } + }, + } +}) + const buildTestSchema = async nodes => { store.dispatch({ type: `DELETE_CACHE` }) for (const node of nodes) { diff --git a/packages/gatsby/src/schema/infer/__tests__/infer.js b/packages/gatsby/src/schema/infer/__tests__/infer.js index 19b7231b4b639..81b9eb4e9267b 100644 --- a/packages/gatsby/src/schema/infer/__tests__/infer.js +++ b/packages/gatsby/src/schema/infer/__tests__/infer.js @@ -12,6 +12,26 @@ const { TypeConflictReporter } = require(`../type-conflict-reporter`) const withResolverContext = require(`../../context`) require(`../../../db/__tests__/fixtures/ensure-loki`)() +jest.mock(`gatsby-cli/lib/reporter`, () => { + return { + log: jest.fn(), + info: jest.fn(), + warn: jest.fn(), + error: jest.fn(), + activityTimer: () => { + return { + start: jest.fn(), + setStatus: jest.fn(), + end: jest.fn(), + } + }, + } +}) +const report = require(`gatsby-cli/lib/reporter`) +afterEach(() => { + report.error.mockClear() +}) + const makeNodes = () => [ { id: `foo`, diff --git a/packages/gatsby/src/schema/infer/__tests__/merge-types.js b/packages/gatsby/src/schema/infer/__tests__/merge-types.js index ced13aeedaf32..1c467ae3776ba 100644 --- a/packages/gatsby/src/schema/infer/__tests__/merge-types.js +++ b/packages/gatsby/src/schema/infer/__tests__/merge-types.js @@ -3,6 +3,22 @@ const { store } = require(`../../../redux`) const { build } = require(`../..`) require(`../../../db/__tests__/fixtures/ensure-loki`)() +jest.mock(`gatsby-cli/lib/reporter`, () => { + return { + log: jest.fn(), + info: jest.fn(), + warn: jest.fn(), + error: jest.fn(), + activityTimer: () => { + return { + start: jest.fn(), + setStatus: jest.fn(), + end: jest.fn(), + } + }, + } +}) + const nodes = [ { id: `id1`, diff --git a/packages/gatsby/src/schema/schema.js b/packages/gatsby/src/schema/schema.js index 1286d1543b883..73788f630a438 100644 --- a/packages/gatsby/src/schema/schema.js +++ b/packages/gatsby/src/schema/schema.js @@ -108,19 +108,39 @@ const updateSchemaComposer = async ({ typeConflictReporter, parentSpan, }) => { - await addTypes({ schemaComposer, parentSpan, types }) + let activity = report.activityTimer(`Add explicit types`, { + parentSpan: parentSpan, + }) + activity.start() + await addTypes({ schemaComposer, parentSpan: activity.span, types }) + activity.end() + + activity = report.activityTimer(`Add inferred types`, { + parentSpan: parentSpan, + }) + activity.start() await addInferredTypes({ schemaComposer, nodeStore, typeConflictReporter, typeMapping, - parentSpan, + parentSpan: activity.span, + }) + activity.end() + + activity = report.activityTimer(`Processing types`, { + parentSpan: parentSpan, + }) + activity.start() + await printTypeDefinitions({ + config: printConfig, + schemaComposer, + parentSpan: activity.span, }) - await printTypeDefinitions({ config: printConfig, schemaComposer }) await addSetFieldsOnGraphQLNodeTypeFields({ schemaComposer, nodeStore, - parentSpan, + parentSpan: activity.span, }) await Promise.all( Array.from(new Set(schemaComposer.values())).map(typeComposer => @@ -129,14 +149,22 @@ const updateSchemaComposer = async ({ typeComposer, fieldExtensions, nodeStore, - parentSpan, + parentSpan: activity.span, }) ) ) - checkQueryableInterfaces({ schemaComposer }) - await addConvenienceChildrenFields({ schemaComposer, parentSpan }) - await addThirdPartySchemas({ schemaComposer, thirdPartySchemas, parentSpan }) - await addCustomResolveFunctions({ schemaComposer, parentSpan }) + checkQueryableInterfaces({ schemaComposer, parentSpan: activity.span }) + await addConvenienceChildrenFields({ + schemaComposer, + parentSpan: activity.span, + }) + await addThirdPartySchemas({ + schemaComposer, + thirdPartySchemas, + parentSpan: activity.span, + }) + await addCustomResolveFunctions({ schemaComposer, parentSpan: activity.span }) + activity.end() } const processTypeComposer = async ({ diff --git a/packages/gatsby/src/schema/types/__tests__/date.js b/packages/gatsby/src/schema/types/__tests__/date.js index af9f44cf9b5fe..7972dfb1ef489 100644 --- a/packages/gatsby/src/schema/types/__tests__/date.js +++ b/packages/gatsby/src/schema/types/__tests__/date.js @@ -4,6 +4,22 @@ const withResolverContext = require(`../../context`) const { isDate, looksLikeADate } = require(`../date`) require(`../../../db/__tests__/fixtures/ensure-loki`)() +jest.mock(`gatsby-cli/lib/reporter`, () => { + return { + log: jest.fn(), + info: jest.fn(), + warn: jest.fn(), + error: jest.fn(), + activityTimer: () => { + return { + start: jest.fn(), + setStatus: jest.fn(), + end: jest.fn(), + } + }, + } +}) + // Timestamps grabbed from https://github.com/moment/moment/blob/2e2a5b35439665d4b0200143d808a7c26d6cd30f/src/test/moment/is_valid.js describe(`isDate`, () => { diff --git a/packages/gatsby/src/schema/types/__tests__/filter-input.js b/packages/gatsby/src/schema/types/__tests__/filter-input.js index 92c868a0ba017..7d6af7cd39c80 100644 --- a/packages/gatsby/src/schema/types/__tests__/filter-input.js +++ b/packages/gatsby/src/schema/types/__tests__/filter-input.js @@ -2,6 +2,22 @@ const { build } = require(`../..`) const { store } = require(`../../../redux`) require(`../../../db/__tests__/fixtures/ensure-loki`)() +jest.mock(`gatsby-cli/lib/reporter`, () => { + return { + log: jest.fn(), + info: jest.fn(), + warn: jest.fn(), + error: jest.fn(), + activityTimer: () => { + return { + start: jest.fn(), + setStatus: jest.fn(), + end: jest.fn(), + } + }, + } +}) + const nodes = [ { id: `parent`, diff --git a/packages/gatsby/src/utils/__tests__/webpack.config.js b/packages/gatsby/src/utils/__tests__/webpack.config.js index 544a792599b81..288cec0e37fe3 100644 --- a/packages/gatsby/src/utils/__tests__/webpack.config.js +++ b/packages/gatsby/src/utils/__tests__/webpack.config.js @@ -18,6 +18,22 @@ const { readFileSync } = require(`fs-extra`) const webpackConfig = require(`../webpack.config`) const { store } = require(`../../redux`) +jest.mock(`gatsby-cli/lib/reporter`, () => { + return { + log: jest.fn(), + info: jest.fn(), + warn: jest.fn(), + error: jest.fn(), + activityTimer: () => { + return { + start: jest.fn(), + setStatus: jest.fn(), + end: jest.fn(), + } + }, + } +}) + beforeEach(() => { DefinePlugin.mockClear() readFileSync.mockClear() diff --git a/packages/gatsby/src/utils/webpack.config.js b/packages/gatsby/src/utils/webpack.config.js index ef2bbf90e6bc0..ebae375a1eb3f 100644 --- a/packages/gatsby/src/utils/webpack.config.js +++ b/packages/gatsby/src/utils/webpack.config.js @@ -23,7 +23,13 @@ const hasLocalEslint = require(`./local-eslint-config-finder`) // 3) build-javascript: Build JS and CSS chunks for production // 4) build-html: build all HTML files -module.exports = async (program, directory, suppliedStage) => { +module.exports = async ( + program, + directory, + suppliedStage, + port, + { parentSpan } = {} +) => { const modulesThatUseGatsby = await getGatsbyDependents() const directoryPath = withBasePath(directory) @@ -560,6 +566,7 @@ module.exports = async (program, directory, suppliedStage) => { rules, loaders, plugins, + parentSpan, }) return getConfig()