From 76523e41433e3079fd2a0f14d2e4b77ae9041371 Mon Sep 17 00:00:00 2001 From: Maya Raman Date: Tue, 28 Nov 2023 12:29:08 -0500 Subject: [PATCH 01/13] surface level files building --- gatsby-config.mjs | 38 +++ package.json | 2 +- .../gatsby-node.mjs | 264 +++++++++++++++ .../gatsby-source-snooty-prod/gatsby-node.mjs | 310 ++++++++++++++++++ 4 files changed, 613 insertions(+), 1 deletion(-) create mode 100644 gatsby-config.mjs create mode 100644 plugins/gatsby-source-snooty-preview/gatsby-node.mjs create mode 100644 plugins/gatsby-source-snooty-prod/gatsby-node.mjs diff --git a/gatsby-config.mjs b/gatsby-config.mjs new file mode 100644 index 000000000..846f62c50 --- /dev/null +++ b/gatsby-config.mjs @@ -0,0 +1,38 @@ +import { createRequire } from 'module'; +import { generatePathPrefix } from './src/utils/generate-path-prefix.js'; +import { siteMetadata } from './src/utils/site-metadata.js'; +import { isGatsbyPreview } from './src/utils/is-gatsby-preview.js'; + +const isPreview = isGatsbyPreview(); +const pathPrefix = !isPreview ? generatePathPrefix(siteMetadata) : undefined; + +const require = createRequire(import.meta.url); + +console.log('PATH PREFIX', pathPrefix); + +// Specifies which plugins to use depending on build environment +const plugins = ['gatsby-plugin-emotion', isPreview ? 'gatsby-source-snooty-preview' : 'gatsby-source-snooty-prod']; + +// PRODUCTION DEPLOYMENTS -- +// If not a preview build, use the layout that includes the +// consistent navbar and footer and generate a sitemap. +if (!isPreview) { + plugins.push(`gatsby-plugin-sitemap`); + const layoutComponentRelativePath = `./src/layouts/index.js`; + plugins.push({ + resolve: 'gatsby-plugin-layout', + options: { + component: require.resolve(layoutComponentRelativePath), + }, + }); +} else { + const layoutComponentRelativePath = `./src/layouts/preview-layout-outer.js`; + plugins.push({ + resolve: 'gatsby-plugin-layout', + options: { + component: require.resolve(layoutComponentRelativePath), + }, + }); +} + +export { plugins, pathPrefix, siteMetadata }; diff --git a/package.json b/package.json index 25246d22b..5da746b8c 100644 --- a/package.json +++ b/package.json @@ -102,7 +102,7 @@ "clipboard": "^2.0.8", "dotenv": "^8.2.0", "eventsource": "^2.0.2", - "gatsby": "^5.0.0", + "gatsby": "^5.3.0", "gatsby-plugin-emotion": "^8.0.0", "gatsby-plugin-google-tagmanager": "^5.0.0", "gatsby-plugin-layout": "^4.7.0", diff --git a/plugins/gatsby-source-snooty-preview/gatsby-node.mjs b/plugins/gatsby-source-snooty-preview/gatsby-node.mjs new file mode 100644 index 000000000..2254230a5 --- /dev/null +++ b/plugins/gatsby-source-snooty-preview/gatsby-node.mjs @@ -0,0 +1,264 @@ +import { getDataStore } from 'gatsby/dist/datastore'; +import path from 'path'; +import { dirname } from 'path'; +import { fileURLToPath } from 'url'; +import stream from 'stream'; +import { promisify } from 'util'; +import got from 'got'; +import { createRequire } from 'module'; +import { parser } from 'stream-json/jsonl/Parser'; +import { sourceNodes } from './other-things-to-source.js'; +import { fetchClientAccessToken } from './utils/kanopy-auth.js'; +import { callPostBuildWebhook } from './utils/post-build.js'; +import { + consumeData, + createSnootyMetadataId, + KEY_LAST_FETCHED, + KEY_LAST_CLIENT_ACCESS_TOKEN, +} from './utils/data-consumer.js'; + +const pipeline = promisify(stream.pipeline); + +// Global variable to allow webhookBody from sourceNodes step to be passed down +// to other Gatsby build steps that might not pass webhookBody natively. +let currentWebhookBody = {}; + +export const createSchemaCustomization = async ({ actions }) => { + const { createTypes } = actions; + const typeDefs = ` + type Page implements Node @dontInfer { + page_id: String + branch: String + pagePath: String + ast: JSON! + metadata: SnootyMetadata @link + } + + type PagePath implements Node @dontInfer { + page_id: String! + branch: String! + project: String! + pageNodeId: String! + } + + type SnootyMetadata implements Node @dontInfer { + metadata: JSON + branch: String + project: String + } + + type RemoteMetadata implements Node @dontInfer { + remoteMetadata: JSON + } + + type ChangelogData implements Node @dontInfer { + changelogData: JSON + } + `; + createTypes(typeDefs); +}; + +const APIBase = process.env.API_BASE || `https://snooty-data-api.mongodb.com`; +const GATSBY_CLOUD_SITE_USER = process.env.GATSBY_CLOUD_SITE_USER; + +let isFirstRun = true; +export const sourceNodes = async ({ + actions, + createNodeId, + getNode, + getNodesByType, + reporter, + createContentDigest, + cache, + webhookBody, +}) => { + console.log({ webhookBody }); + currentWebhookBody = webhookBody; + let hasOpenAPIChangelog = false; + const { createNode, touchNode } = actions; + + const fileWritePromises = []; + const lastFetched = (await cache.get(KEY_LAST_FETCHED)) || 0; + const lastClientAccessToken = await cache.get(KEY_LAST_CLIENT_ACCESS_TOKEN); + console.log({ lastFetched }); + + if (isFirstRun && lastFetched) { + // nodes of following types are managed statefully: + // SnootyMetadata, Page, PagePath + // we need to touch on them on delta updates on first run of a process to prevent them from being garbage collected + const datastore = getDataStore(); + for (const nodeType of ['SnootyMetadata', 'Page', 'PagePath']) { + for (const node of datastore.iterateNodesByType(nodeType)) { + touchNode(node); + } + } + } + + try { + if (!GATSBY_CLOUD_SITE_USER) { + throw new Error('Missing GATSBY_CLOUD_SITE_USER'); + } + + // Generate client access token only if trying to access Snooty Data API's staging instance + const clientAccessToken = APIBase.includes('.staging') ? await fetchClientAccessToken(lastClientAccessToken) : ''; + let url; + if (lastFetched) { + url = `${APIBase}/user/${GATSBY_CLOUD_SITE_USER}/documents?updated=${lastFetched}`; + } else { + url = `${APIBase}/user/${GATSBY_CLOUD_SITE_USER}/documents`; + } + + const headers = {}; + if (clientAccessToken) { + headers['Authorization'] = `Bearer ${clientAccessToken}`; + } + const httpStream = got.stream(url, { headers }); + + let pageCount = 0; + // Callback function to be ran after a valid page has been found and handled. + // Tracks and updates information that spans across several data entries + const onHandlePage = (pageTemplate, pageId, pageNodeId) => { + if (pageTemplate === 'changelog') hasOpenAPIChangelog = true; + pageCount += 1; + if (pageCount % 1000 === 0) { + console.log({ pageCount, page_id: pageId, id: pageNodeId }); + } + }; + + // Since there's a lot of data incoming from the Snooty Data API, we stream + // the data in chunks and parse them as they come instead of fetching everything + // as a single JSON response + const decode = parser(); + decode.on('data', async (_entry) => { + // Un-nest data + const entry = _entry.value; + await consumeData(entry, { + actions, + cache, + clientAccessToken, + createContentDigest, + createNodeId, + fileWritePromises, + getNode, + onHandlePage, + }); + }); + + console.time(`source updates`); + // Wait for HTTP connection to close. + await pipeline(httpStream, decode); + console.timeEnd(`source updates`); + } catch (error) { + callPostBuildWebhook(webhookBody, 'failed'); + reporter.panic('There was an issue sourcing nodes', error); + } + + // Wait for all assets to be written. + await Promise.all(fileWritePromises); + + // Source old nodes. + console.time(`old source nodes`); + await sourceNodes({ + hasOpenAPIChangelog, + github_username: GATSBY_CLOUD_SITE_USER, + createNode, + createContentDigest, + createNodeId, + getNodesByType, + }); + console.timeEnd(`old source nodes`); + isFirstRun = false; +}; + +// Prevent errors when running gatsby build caused by browser packages run in a node environment. +export const onCreateWebpackConfig = ({ plugins, actions }) => { + const require = createRequire(import.meta.url); + + const providePlugins = { + Buffer: ['buffer', 'Buffer'], + process: require.resolve('../../stubs/process.js'), + }; + + const fallbacks = { stream: require.resolve('stream-browserify'), buffer: require.resolve('buffer/') }; + + actions.setWebpackConfig({ + plugins: [plugins.provide(providePlugins)], + resolve: { + fallback: fallbacks, + alias: { + process: 'process/browser', + }, + }, + }); +}; + +export const createPages = async ({ actions, createNodeId, getNode, graphql, reporter }) => { + const { createPage } = actions; + const __dirname = dirname(fileURLToPath(import.meta.url)); + const templatePath = path.join(__dirname, `../../src/components/DocumentBodyPreview.js`); + const result = await graphql(` + query { + allPagePath { + totalCount + nodes { + pageNodeId + branch + page_id + project + } + allProjects: distinct(field: { project: SELECT }) + } + } + `); + + if (result.errors) { + await callPostBuildWebhook(currentWebhookBody, 'failed'); + reporter.panic('There was an error in the graphql query', result.errors); + } + + try { + result.data.allPagePath.nodes.forEach((node) => { + const pagePath = path.join(node.project, node.branch, node.page_id); + let slug = node.page_id; + // Slices off leading slash to ensure slug matches an entry within the toctreeOrder and renders InternalPageNav components + if (slug !== '/' && slug[0] === '/') slug = slug.slice(1); + + const metadataNodeId = createSnootyMetadataId({ createNodeId, branch: node.branch, project: node.project }); + if (!getNode(metadataNodeId)) { + // Take into account the possibility of having new page data available through the API, + // but no metadata yet due to async uploads + console.warn( + `Skipping node creation for page "${node.page_id}", in project "${node.project}" on branch "${node.branch}". No metadata node "${metadataNodeId}" found.` + ); + return; + } + + createPage({ + path: pagePath, + component: templatePath, + context: { + id: node.pageNodeId, + slug, + // Hardcode static/safe values to prevent incremental builds from rebuilding versioned preview pages + repoBranches: {}, + associatedReposInfo: {}, + isAssociatedProduct: false, + project: node.project, + }, + }); + }); + } catch (err) { + await callPostBuildWebhook(currentWebhookBody, 'failed'); + reporter.panic('Could not build pages off of graphl query', err); + } +}; + +// `onPostBuild` is run by Gatsby Cloud after everything is built, but before the +// content is deployed to the preview site. This can result in a short delay between +// when the post-build webhook is called and when the content is updated. +// Ideally, we would use Gatsby Cloud's Outgoing Notifications feature once it can +// support passing through custom data from the preview webhook's body (to include the +// Autobuilder job ID associated with the GC build). +export const onPostBuild = async () => { + await callPostBuildWebhook(currentWebhookBody, 'completed'); +}; diff --git a/plugins/gatsby-source-snooty-prod/gatsby-node.mjs b/plugins/gatsby-source-snooty-prod/gatsby-node.mjs new file mode 100644 index 000000000..57b75530d --- /dev/null +++ b/plugins/gatsby-source-snooty-prod/gatsby-node.mjs @@ -0,0 +1,310 @@ +import path from 'path'; +import { dirname } from 'path'; +import { fileURLToPath } from 'url'; +import { createRequire } from 'module'; +import { transformBreadcrumbs } from '../../src/utils/setup/transform-breadcrumbs.js'; +import { saveAssetFiles, saveStaticFiles } from '../../src/utils/setup/save-asset-files.js'; +import { validateEnvVariables } from '../../src/utils/setup/validate-env-variables.js'; +import { getNestedValue } from '../../src/utils/get-nested-value.js'; +import { removeNestedValue } from '../../src/utils/remove-nested-value.js'; +import { getPageSlug } from '../../src/utils/get-page-slug.js'; +import { manifestMetadata, siteMetadata } from '../../src/utils/site-metadata.js'; +import { assertTrailingSlash } from '../../src/utils/assert-trailing-slash.js'; +import { constructPageIdPrefix } from '../../src/utils/setup/construct-page-id-prefix.js'; +import { manifestDocumentDatabase, realmDocumentDatabase } from '../../src/init/DocumentDatabase.js'; +import { createOpenAPIChangelogNode } from '../utils/openapi.js'; +import { createProductNodes } from '../utils/products.js'; + +// different types of references +const PAGES = []; + +// in-memory object with key/value = filename/document +let RESOLVED_REF_DOC_MAPPING = {}; + +const assets = new Map(); + +let db; + +let isAssociatedProduct = false; +const associatedReposInfo = {}; + +// Creates node for RemoteMetadata, mostly used for Embedded Versions. If no associated products +// or data are found, the node will be null +const createRemoteMetadataNode = async ({ createNode, createNodeId, createContentDigest }) => { + // fetch associated child products + const productList = manifestMetadata?.associated_products || []; + await Promise.all( + productList.map(async (product) => { + associatedReposInfo[product.name] = await db.realmInterface.fetchDocset({ project: product.name }); + }) + ); + // check if product is associated child product + try { + const umbrellaProduct = await db.realmInterface.getMetadata({ + 'associated_products.name': siteMetadata.project, + }); + isAssociatedProduct = !!umbrellaProduct; + } catch (e) { + console.log('No umbrella product found. Not an associated product.'); + isAssociatedProduct = false; + } + + // get remote metadata for updated ToC in Atlas + try { + const filter = { + project: manifestMetadata.project, + branch: manifestMetadata.branch, + }; + if (isAssociatedProduct || manifestMetadata?.associated_products?.length) { + filter['is_merged_toc'] = true; + } + const findOptions = { + sort: { build_id: -1 }, + }; + const remoteMetadata = await db.realmInterface.getMetadata(filter, findOptions); + + createNode({ + children: [], + id: createNodeId('remoteMetadata'), + internal: { + contentDigest: createContentDigest(remoteMetadata), + type: 'RemoteMetadata', + }, + parent: null, + remoteMetadata: remoteMetadata, + }); + } catch (e) { + console.error('Error while fetching metadata from Atlas, falling back to manifest metadata'); + console.error(e); + } +}; + +export const sourceNodes = async ({ actions, createContentDigest, createNodeId }) => { + let hasOpenAPIChangelog = false; + const { createNode } = actions; + + // setup and validate env variables + const envResults = validateEnvVariables(manifestMetadata); + if (envResults.error) { + throw Error(envResults.message); + } + + // wait to connect to Realm + + if (siteMetadata.manifestPath) { + console.log('Loading documents from manifest'); + db = manifestDocumentDatabase; + } else { + console.log('Loading documents from realm'); + db = realmDocumentDatabase; + } + + await db.connect(); + + const documents = await db.getDocuments(); + + if (documents.length === 0) { + console.error( + 'Snooty could not find AST entries for the', + siteMetadata.parserBranch, + 'branch of', + siteMetadata.project, + 'within', + siteMetadata.database + ); + process.exit(1); + } + const pageIdPrefix = constructPageIdPrefix(siteMetadata); + documents.forEach((doc) => { + const { page_id, ...rest } = doc; + RESOLVED_REF_DOC_MAPPING[page_id.replace(`${pageIdPrefix}/`, '')] = rest; + }); + + // Identify page documents and parse each document for images + Object.entries(RESOLVED_REF_DOC_MAPPING).forEach(([key, val]) => { + const pageNode = getNestedValue(['ast', 'children'], val); + const filename = getNestedValue(['filename'], val) || ''; + + // Parse each document before pages are created via createPage + // to remove all positions fields as it is only used in the parser for logging + removeNestedValue('position', 'children', [val?.ast]); + + if (pageNode) { + val.static_assets.forEach((asset) => { + const checksum = asset.checksum; + if (assets.has(checksum)) { + assets.set(checksum, new Set([...assets.get(checksum), asset.key])); + } else { + assets.set(checksum, new Set([asset.key])); + } + }); + } + + if (filename.endsWith('.txt') && !manifestMetadata.openapi_pages?.[key]) { + PAGES.push(key); + } + if (val?.ast?.options?.template === 'changelog') hasOpenAPIChangelog = true; + }); + + await createProductNodes({ db, createNode, createNodeId, createContentDigest }); + + await createRemoteMetadataNode({ createNode, createNodeId, createContentDigest }); + if (siteMetadata.project === 'cloud-docs' && hasOpenAPIChangelog) + await createOpenAPIChangelogNode({ createNode, createNodeId, createContentDigest, siteMetadata, db }); + + await saveAssetFiles(assets, db); + const { static_files: staticFiles, ...metadataMinusStatic } = await db.getMetadata(); + + const { parentPaths, slugToTitle } = metadataMinusStatic; + if (parentPaths) { + transformBreadcrumbs(parentPaths, slugToTitle); + } + + //Save files in the static_files field of metadata document, including intersphinx inventories + if (staticFiles) { + await saveStaticFiles(staticFiles); + } + + createNode({ + children: [], + id: createNodeId('metadata'), + internal: { + contentDigest: createContentDigest(metadataMinusStatic), + type: 'SnootyMetadata', + }, + parent: null, + metadata: metadataMinusStatic, + }); +}; + +export const createPages = async ({ actions }) => { + const { createPage } = actions; + const __dirname = dirname(fileURLToPath(import.meta.url)); + + let repoBranches = null; + try { + const repoInfo = await db.realmInterface.fetchDocset(); + let errMsg; + + if (!repoInfo) { + errMsg = `Repo data for ${siteMetadata.project} could not be found.`; + } + + // We should expect the number of branches for a docs repo to be 1 or more. + if (!repoInfo.branches?.length) { + errMsg = `No version information found for ${siteMetadata.project}`; + } + + if (errMsg) { + throw errMsg; + } + + // Handle inconsistent env names. Default to 'dotcomprd' when possible since this is what we will most likely use. + // dotcom environments seem to be consistent. + let envKey = siteMetadata.snootyEnv; + if (!envKey || envKey === 'development') { + envKey = 'dotcomprd'; + } else if (envKey === 'production') { + envKey = 'prd'; + } else if (envKey === 'staging') { + envKey = 'stg'; + } + + // We're overfetching data here. We only need branches and prefix at the least + repoBranches = { + branches: repoInfo.branches, + siteBasePrefix: repoInfo.prefix[envKey], + }; + + if (repoInfo.groups?.length > 0) { + repoBranches.groups = repoInfo.groups; + } + } catch (err) { + console.error(err); + throw err; + } + + return new Promise((resolve, reject) => { + PAGES.forEach((page) => { + const pageNodes = RESOLVED_REF_DOC_MAPPING[page]?.ast; + const slug = getPageSlug(page); + + // TODO: Gatsby v4 will enable code splitting automatically. Delete duplicate component, add conditional for consistent-nav UnifiedFooter + const mainComponentRelativePath = `../../src/components/DocumentBody.js`; + + if (RESOLVED_REF_DOC_MAPPING[page] && Object.keys(RESOLVED_REF_DOC_MAPPING[page]).length > 0) { + createPage({ + path: assertTrailingSlash(slug), + component: path.resolve(__dirname, mainComponentRelativePath), + context: { + slug, + repoBranches, + associatedReposInfo, + isAssociatedProduct, + template: pageNodes?.options?.template, + page: pageNodes, + }, + }); + } + }); + + resolve(); + }); +}; + +// Prevent errors when running gatsby build caused by browser packages run in a node environment. +export const onCreateWebpackConfig = ({ plugins, actions }) => { + const require = createRequire(import.meta.url); + + const providePlugins = { + Buffer: ['buffer', 'Buffer'], + process: require.resolve('../../stubs/process.js'), + }; + + const fallbacks = { stream: require.resolve('stream-browserify'), buffer: require.resolve('buffer/') }; + + actions.setWebpackConfig({ + plugins: [plugins.provide(providePlugins)], + resolve: { + fallback: fallbacks, + alias: { + process: 'process/browser', + }, + }, + }); +}; + +// Remove type inference, as our schema is too ambiguous for this to be useful. +// https://www.gatsbyjs.com/docs/scaling-issues/#switch-off-type-inference-for-sitepagecontext +export const createSchemaCustomization = ({ actions }) => { + actions.createTypes(` + type Page implements Node @dontInfer { + page_id: String + branch: String + pagePath: String + ast: JSON! + metadata: SnootyMetadata @link + } + + type SnootyMetadata implements Node @dontInfer { + metadata: JSON + branch: String + project: String + } + + type PagePath implements Node @dontInfer { + page_id: String! + branch: String! + project: String! + pageNodeId: String! + } + + type RemoteMetadata implements Node @dontInfer { + remoteMetadata: JSON + } + + type ChangelogData implements Node @dontInfer { + changelogData: JSON + } + `); +}; From 62482fd7591d524b968544efa6611accf9020f15 Mon Sep 17 00:00:00 2001 From: Maya Raman Date: Tue, 28 Nov 2023 14:38:27 -0500 Subject: [PATCH 02/13] working up until crashing from cache, retry without type:module --- gatsby-config.js | 39 --- package.json | 1 + .../gatsby-node.js | 257 --------------- .../gatsby-source-snooty-prod/gatsby-node.js | 304 ------------------ plugins/utils/openapi.js | 6 +- plugins/utils/products.js | 6 +- src/build-constants.js | 12 +- .../utils/filterHiddenChanges.js | 2 +- src/init/DocumentDatabase.js | 18 +- src/utils/assert-trailing-slash.js | 2 +- src/utils/base-url.js | 4 +- src/utils/generate-path-prefix.js | 6 +- src/utils/get-nested-value.js | 4 +- src/utils/get-page-slug.js | 2 +- src/utils/get-plaintext.js | 2 +- src/utils/is-gatsby-preview.js | 2 +- src/utils/normalize-path.js | 2 +- src/utils/remove-nested-value.js | 2 +- src/utils/setup/construct-build-filter.js | 4 +- src/utils/setup/construct-page-id-prefix.js | 2 +- src/utils/setup/fetch-manifest-metadata.js | 6 +- src/utils/setup/init-realm.js | 6 +- src/utils/setup/save-asset-files.js | 6 +- src/utils/setup/transform-breadcrumbs.js | 4 +- src/utils/setup/validate-env-variables.js | 4 +- src/utils/site-metadata.js | 14 +- 26 files changed, 56 insertions(+), 661 deletions(-) delete mode 100644 gatsby-config.js delete mode 100644 plugins/gatsby-source-snooty-preview/gatsby-node.js delete mode 100644 plugins/gatsby-source-snooty-prod/gatsby-node.js diff --git a/gatsby-config.js b/gatsby-config.js deleted file mode 100644 index a1ca68e57..000000000 --- a/gatsby-config.js +++ /dev/null @@ -1,39 +0,0 @@ -const { generatePathPrefix } = require('./src/utils/generate-path-prefix'); -const { siteMetadata } = require('./src/utils/site-metadata'); -const { isGatsbyPreview } = require('./src/utils/is-gatsby-preview'); - -const isPreview = isGatsbyPreview(); -const pathPrefix = !isPreview ? generatePathPrefix(siteMetadata) : undefined; - -console.log('PATH PREFIX', pathPrefix); - -// Specifies which plugins to use depending on build environment -const plugins = ['gatsby-plugin-emotion', isPreview ? 'gatsby-source-snooty-preview' : 'gatsby-source-snooty-prod']; - -// PRODUCTION DEPLOYMENTS -- -// If not a preview build, use the layout that includes the -// consistent navbar and footer and generate a sitemap. -if (!isPreview) { - plugins.push(`gatsby-plugin-sitemap`); - const layoutComponentRelativePath = `./src/layouts/index.js`; - plugins.push({ - resolve: 'gatsby-plugin-layout', - options: { - component: require.resolve(layoutComponentRelativePath), - }, - }); -} else { - const layoutComponentRelativePath = `./src/layouts/preview-layout-outer.js`; - plugins.push({ - resolve: 'gatsby-plugin-layout', - options: { - component: require.resolve(layoutComponentRelativePath), - }, - }); -} - -module.exports = { - plugins, - pathPrefix, - siteMetadata, -}; diff --git a/package.json b/package.json index 5da746b8c..c9252d662 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,7 @@ { "name": "snooty", "version": "0.15.1", + "type": "module", "repository": "github:mongodb/snooty", "engines": { "node": "^18", diff --git a/plugins/gatsby-source-snooty-preview/gatsby-node.js b/plugins/gatsby-source-snooty-preview/gatsby-node.js deleted file mode 100644 index 9a7820842..000000000 --- a/plugins/gatsby-source-snooty-preview/gatsby-node.js +++ /dev/null @@ -1,257 +0,0 @@ -const { getDataStore } = require('gatsby/dist/datastore'); -const path = require('path'); -const stream = require('stream'); -const { promisify } = require('util'); -const pipeline = promisify(stream.pipeline); -const got = require(`got`); -const { parser } = require(`stream-json/jsonl/Parser`); -const { sourceNodes } = require(`./other-things-to-source`); -const { fetchClientAccessToken } = require('./utils/kanopy-auth.js'); -const { callPostBuildWebhook } = require('./utils/post-build.js'); -const { - consumeData, - createSnootyMetadataId, - KEY_LAST_FETCHED, - KEY_LAST_CLIENT_ACCESS_TOKEN, -} = require('./utils/data-consumer.js'); - -// Global variable to allow webhookBody from sourceNodes step to be passed down -// to other Gatsby build steps that might not pass webhookBody natively. -let currentWebhookBody = {}; - -exports.createSchemaCustomization = async ({ actions }) => { - const { createTypes } = actions; - const typeDefs = ` - type Page implements Node @dontInfer { - page_id: String - branch: String - pagePath: String - ast: JSON! - metadata: SnootyMetadata @link - } - - type PagePath implements Node @dontInfer { - page_id: String! - branch: String! - project: String! - pageNodeId: String! - } - - type SnootyMetadata implements Node @dontInfer { - metadata: JSON - branch: String - project: String - } - - type RemoteMetadata implements Node @dontInfer { - remoteMetadata: JSON - } - - type ChangelogData implements Node @dontInfer { - changelogData: JSON - } - `; - createTypes(typeDefs); -}; - -const APIBase = process.env.API_BASE || `https://snooty-data-api.mongodb.com`; -const GATSBY_CLOUD_SITE_USER = process.env.GATSBY_CLOUD_SITE_USER; - -let isFirstRun = true; -exports.sourceNodes = async ({ - actions, - createNodeId, - getNode, - getNodesByType, - reporter, - createContentDigest, - cache, - webhookBody, -}) => { - console.log({ webhookBody }); - currentWebhookBody = webhookBody; - let hasOpenAPIChangelog = false; - const { createNode, touchNode } = actions; - - const fileWritePromises = []; - const lastFetched = (await cache.get(KEY_LAST_FETCHED)) || 0; - const lastClientAccessToken = await cache.get(KEY_LAST_CLIENT_ACCESS_TOKEN); - console.log({ lastFetched }); - - if (isFirstRun && lastFetched) { - // nodes of following types are managed statefully: - // SnootyMetadata, Page, PagePath - // we need to touch on them on delta updates on first run of a process to prevent them from being garbage collected - const datastore = getDataStore(); - for (const nodeType of ['SnootyMetadata', 'Page', 'PagePath']) { - for (const node of datastore.iterateNodesByType(nodeType)) { - touchNode(node); - } - } - } - - try { - if (!GATSBY_CLOUD_SITE_USER) { - throw new Error('Missing GATSBY_CLOUD_SITE_USER'); - } - - // Generate client access token only if trying to access Snooty Data API's staging instance - const clientAccessToken = APIBase.includes('.staging') ? await fetchClientAccessToken(lastClientAccessToken) : ''; - let url; - if (lastFetched) { - url = `${APIBase}/user/${GATSBY_CLOUD_SITE_USER}/documents?updated=${lastFetched}`; - } else { - url = `${APIBase}/user/${GATSBY_CLOUD_SITE_USER}/documents`; - } - - const headers = {}; - if (clientAccessToken) { - headers['Authorization'] = `Bearer ${clientAccessToken}`; - } - const httpStream = got.stream(url, { headers }); - - let pageCount = 0; - // Callback function to be ran after a valid page has been found and handled. - // Tracks and updates information that spans across several data entries - const onHandlePage = (pageTemplate, pageId, pageNodeId) => { - if (pageTemplate === 'changelog') hasOpenAPIChangelog = true; - pageCount += 1; - if (pageCount % 1000 === 0) { - console.log({ pageCount, page_id: pageId, id: pageNodeId }); - } - }; - - // Since there's a lot of data incoming from the Snooty Data API, we stream - // the data in chunks and parse them as they come instead of fetching everything - // as a single JSON response - const decode = parser(); - decode.on('data', async (_entry) => { - // Un-nest data - const entry = _entry.value; - await consumeData(entry, { - actions, - cache, - clientAccessToken, - createContentDigest, - createNodeId, - fileWritePromises, - getNode, - onHandlePage, - }); - }); - - console.time(`source updates`); - // Wait for HTTP connection to close. - await pipeline(httpStream, decode); - console.timeEnd(`source updates`); - } catch (error) { - callPostBuildWebhook(webhookBody, 'failed'); - reporter.panic('There was an issue sourcing nodes', error); - } - - // Wait for all assets to be written. - await Promise.all(fileWritePromises); - - // Source old nodes. - console.time(`old source nodes`); - await sourceNodes({ - hasOpenAPIChangelog, - github_username: GATSBY_CLOUD_SITE_USER, - createNode, - createContentDigest, - createNodeId, - getNodesByType, - }); - console.timeEnd(`old source nodes`); - isFirstRun = false; -}; - -// Prevent errors when running gatsby build caused by browser packages run in a node environment. -exports.onCreateWebpackConfig = ({ plugins, actions }) => { - const providePlugins = { - Buffer: ['buffer', 'Buffer'], - process: require.resolve('../../stubs/process.js'), - }; - - const fallbacks = { stream: require.resolve('stream-browserify'), buffer: require.resolve('buffer/') }; - - actions.setWebpackConfig({ - plugins: [plugins.provide(providePlugins)], - resolve: { - fallback: fallbacks, - alias: { - process: 'process/browser', - }, - }, - }); -}; - -exports.createPages = async ({ actions, createNodeId, getNode, graphql, reporter }) => { - const { createPage } = actions; - const templatePath = path.join(__dirname, `../../src/components/DocumentBodyPreview.js`); - const result = await graphql(` - query { - allPagePath { - totalCount - nodes { - pageNodeId - branch - page_id - project - } - allProjects: distinct(field: { project: SELECT }) - } - } - `); - - if (result.errors) { - await callPostBuildWebhook(currentWebhookBody, 'failed'); - reporter.panic('There was an error in the graphql query', result.errors); - } - - try { - result.data.allPagePath.nodes.forEach((node) => { - const pagePath = path.join(node.project, node.branch, node.page_id); - let slug = node.page_id; - // Slices off leading slash to ensure slug matches an entry within the toctreeOrder and renders InternalPageNav components - if (slug !== '/' && slug[0] === '/') slug = slug.slice(1); - - const metadataNodeId = createSnootyMetadataId({ createNodeId, branch: node.branch, project: node.project }); - if (!getNode(metadataNodeId)) { - // Take into account the possibility of having new page data available through the API, - // but no metadata yet due to async uploads - console.warn( - `Skipping node creation for page "${node.page_id}", in project "${node.project}" on branch "${node.branch}". No metadata node "${metadataNodeId}" found.` - ); - return; - } - - createPage({ - path: pagePath, - component: templatePath, - context: { - id: node.pageNodeId, - slug, - // Hardcode static/safe values to prevent incremental builds from rebuilding versioned preview pages - repoBranches: {}, - associatedReposInfo: {}, - isAssociatedProduct: false, - project: node.project, - }, - }); - }); - } catch (err) { - await callPostBuildWebhook(currentWebhookBody, 'failed'); - reporter.panic('Could not build pages off of graphl query', err); - } -}; - -// `onPostBuild` is run by Gatsby Cloud after everything is built, but before the -// content is deployed to the preview site. This can result in a short delay between -// when the post-build webhook is called and when the content is updated. -// Ideally, we would use Gatsby Cloud's Outgoing Notifications feature once it can -// support passing through custom data from the preview webhook's body (to include the -// Autobuilder job ID associated with the GC build). -exports.onPostBuild = async () => { - await callPostBuildWebhook(currentWebhookBody, 'completed'); -}; diff --git a/plugins/gatsby-source-snooty-prod/gatsby-node.js b/plugins/gatsby-source-snooty-prod/gatsby-node.js deleted file mode 100644 index 0173a5439..000000000 --- a/plugins/gatsby-source-snooty-prod/gatsby-node.js +++ /dev/null @@ -1,304 +0,0 @@ -const path = require('path'); -const { transformBreadcrumbs } = require('../../src/utils/setup/transform-breadcrumbs.js'); -const { saveAssetFiles, saveStaticFiles } = require('../../src/utils/setup/save-asset-files'); -const { validateEnvVariables } = require('../../src/utils/setup/validate-env-variables'); -const { getNestedValue } = require('../../src/utils/get-nested-value'); -const { removeNestedValue } = require('../../src/utils/remove-nested-value.js'); -const { getPageSlug } = require('../../src/utils/get-page-slug'); -const { manifestMetadata, siteMetadata } = require('../../src/utils/site-metadata'); -const { assertTrailingSlash } = require('../../src/utils/assert-trailing-slash'); -const { constructPageIdPrefix } = require('../../src/utils/setup/construct-page-id-prefix'); -const { manifestDocumentDatabase, realmDocumentDatabase } = require('../../src/init/DocumentDatabase.js'); -const { createOpenAPIChangelogNode } = require('../utils/openapi.js'); -const { createProductNodes } = require('../utils/products.js'); - -// different types of references -const PAGES = []; - -// in-memory object with key/value = filename/document -let RESOLVED_REF_DOC_MAPPING = {}; - -const assets = new Map(); - -let db; - -let isAssociatedProduct = false; -const associatedReposInfo = {}; - -// Creates node for RemoteMetadata, mostly used for Embedded Versions. If no associated products -// or data are found, the node will be null -const createRemoteMetadataNode = async ({ createNode, createNodeId, createContentDigest }) => { - // fetch associated child products - const productList = manifestMetadata?.associated_products || []; - await Promise.all( - productList.map(async (product) => { - associatedReposInfo[product.name] = await db.realmInterface.fetchDocset({ project: product.name }); - }) - ); - // check if product is associated child product - try { - const umbrellaProduct = await db.realmInterface.getMetadata({ - 'associated_products.name': siteMetadata.project, - }); - isAssociatedProduct = !!umbrellaProduct; - } catch (e) { - console.log('No umbrella product found. Not an associated product.'); - isAssociatedProduct = false; - } - - // get remote metadata for updated ToC in Atlas - try { - const filter = { - project: manifestMetadata.project, - branch: manifestMetadata.branch, - }; - if (isAssociatedProduct || manifestMetadata?.associated_products?.length) { - filter['is_merged_toc'] = true; - } - const findOptions = { - sort: { build_id: -1 }, - }; - const remoteMetadata = await db.realmInterface.getMetadata(filter, findOptions); - - createNode({ - children: [], - id: createNodeId('remoteMetadata'), - internal: { - contentDigest: createContentDigest(remoteMetadata), - type: 'RemoteMetadata', - }, - parent: null, - remoteMetadata: remoteMetadata, - }); - } catch (e) { - console.error('Error while fetching metadata from Atlas, falling back to manifest metadata'); - console.error(e); - } -}; - -exports.sourceNodes = async ({ actions, createContentDigest, createNodeId }) => { - let hasOpenAPIChangelog = false; - const { createNode } = actions; - - // setup and validate env variables - const envResults = validateEnvVariables(manifestMetadata); - if (envResults.error) { - throw Error(envResults.message); - } - - // wait to connect to Realm - - if (siteMetadata.manifestPath) { - console.log('Loading documents from manifest'); - db = manifestDocumentDatabase; - } else { - console.log('Loading documents from realm'); - db = realmDocumentDatabase; - } - - await db.connect(); - - const documents = await db.getDocuments(); - - if (documents.length === 0) { - console.error( - 'Snooty could not find AST entries for the', - siteMetadata.parserBranch, - 'branch of', - siteMetadata.project, - 'within', - siteMetadata.database - ); - process.exit(1); - } - const pageIdPrefix = constructPageIdPrefix(siteMetadata); - documents.forEach((doc) => { - const { page_id, ...rest } = doc; - RESOLVED_REF_DOC_MAPPING[page_id.replace(`${pageIdPrefix}/`, '')] = rest; - }); - - // Identify page documents and parse each document for images - Object.entries(RESOLVED_REF_DOC_MAPPING).forEach(([key, val]) => { - const pageNode = getNestedValue(['ast', 'children'], val); - const filename = getNestedValue(['filename'], val) || ''; - - // Parse each document before pages are created via createPage - // to remove all positions fields as it is only used in the parser for logging - removeNestedValue('position', 'children', [val?.ast]); - - if (pageNode) { - val.static_assets.forEach((asset) => { - const checksum = asset.checksum; - if (assets.has(checksum)) { - assets.set(checksum, new Set([...assets.get(checksum), asset.key])); - } else { - assets.set(checksum, new Set([asset.key])); - } - }); - } - - if (filename.endsWith('.txt') && !manifestMetadata.openapi_pages?.[key]) { - PAGES.push(key); - } - if (val?.ast?.options?.template === 'changelog') hasOpenAPIChangelog = true; - }); - - await createProductNodes({ db, createNode, createNodeId, createContentDigest }); - - await createRemoteMetadataNode({ createNode, createNodeId, createContentDigest }); - if (siteMetadata.project === 'cloud-docs' && hasOpenAPIChangelog) - await createOpenAPIChangelogNode({ createNode, createNodeId, createContentDigest, siteMetadata, db }); - - await saveAssetFiles(assets, db); - const { static_files: staticFiles, ...metadataMinusStatic } = await db.getMetadata(); - - const { parentPaths, slugToTitle } = metadataMinusStatic; - if (parentPaths) { - transformBreadcrumbs(parentPaths, slugToTitle); - } - - //Save files in the static_files field of metadata document, including intersphinx inventories - if (staticFiles) { - await saveStaticFiles(staticFiles); - } - - createNode({ - children: [], - id: createNodeId('metadata'), - internal: { - contentDigest: createContentDigest(metadataMinusStatic), - type: 'SnootyMetadata', - }, - parent: null, - metadata: metadataMinusStatic, - }); -}; - -exports.createPages = async ({ actions }) => { - const { createPage } = actions; - - let repoBranches = null; - try { - const repoInfo = await db.realmInterface.fetchDocset(); - let errMsg; - - if (!repoInfo) { - errMsg = `Repo data for ${siteMetadata.project} could not be found.`; - } - - // We should expect the number of branches for a docs repo to be 1 or more. - if (!repoInfo.branches?.length) { - errMsg = `No version information found for ${siteMetadata.project}`; - } - - if (errMsg) { - throw errMsg; - } - - // Handle inconsistent env names. Default to 'dotcomprd' when possible since this is what we will most likely use. - // dotcom environments seem to be consistent. - let envKey = siteMetadata.snootyEnv; - if (!envKey || envKey === 'development') { - envKey = 'dotcomprd'; - } else if (envKey === 'production') { - envKey = 'prd'; - } else if (envKey === 'staging') { - envKey = 'stg'; - } - - // We're overfetching data here. We only need branches and prefix at the least - repoBranches = { - branches: repoInfo.branches, - siteBasePrefix: repoInfo.prefix[envKey], - }; - - if (repoInfo.groups?.length > 0) { - repoBranches.groups = repoInfo.groups; - } - } catch (err) { - console.error(err); - throw err; - } - - return new Promise((resolve, reject) => { - PAGES.forEach((page) => { - const pageNodes = RESOLVED_REF_DOC_MAPPING[page]?.ast; - const slug = getPageSlug(page); - - // TODO: Gatsby v4 will enable code splitting automatically. Delete duplicate component, add conditional for consistent-nav UnifiedFooter - const mainComponentRelativePath = `../../src/components/DocumentBody.js`; - - if (RESOLVED_REF_DOC_MAPPING[page] && Object.keys(RESOLVED_REF_DOC_MAPPING[page]).length > 0) { - createPage({ - path: assertTrailingSlash(slug), - component: path.resolve(__dirname, mainComponentRelativePath), - context: { - slug, - repoBranches, - associatedReposInfo, - isAssociatedProduct, - template: pageNodes?.options?.template, - page: pageNodes, - }, - }); - } - }); - - resolve(); - }); -}; - -// Prevent errors when running gatsby build caused by browser packages run in a node environment. -exports.onCreateWebpackConfig = ({ plugins, actions }) => { - const providePlugins = { - Buffer: ['buffer', 'Buffer'], - process: require.resolve('../../stubs/process.js'), - }; - - const fallbacks = { stream: require.resolve('stream-browserify'), buffer: require.resolve('buffer/') }; - - actions.setWebpackConfig({ - plugins: [plugins.provide(providePlugins)], - resolve: { - fallback: fallbacks, - alias: { - process: 'process/browser', - }, - }, - }); -}; - -// Remove type inference, as our schema is too ambiguous for this to be useful. -// https://www.gatsbyjs.com/docs/scaling-issues/#switch-off-type-inference-for-sitepagecontext -exports.createSchemaCustomization = ({ actions }) => { - actions.createTypes(` - type Page implements Node @dontInfer { - page_id: String - branch: String - pagePath: String - ast: JSON! - metadata: SnootyMetadata @link - } - - type SnootyMetadata implements Node @dontInfer { - metadata: JSON - branch: String - project: String - } - - type PagePath implements Node @dontInfer { - page_id: String! - branch: String! - project: String! - pageNodeId: String! - } - - type RemoteMetadata implements Node @dontInfer { - remoteMetadata: JSON - } - - type ChangelogData implements Node @dontInfer { - changelogData: JSON - } - `); -}; diff --git a/plugins/utils/openapi.js b/plugins/utils/openapi.js index 96700bd39..90eaa4d56 100644 --- a/plugins/utils/openapi.js +++ b/plugins/utils/openapi.js @@ -1,4 +1,4 @@ -const { hideChanges, hideDiffChanges } = require('../../src/components/OpenAPIChangelog/utils/filterHiddenChanges'); +import { hideChanges, hideDiffChanges } from '../../src/components/OpenAPIChangelog/utils/filterHiddenChanges.js'; const atlasAdminProdChangelogS3Prefix = 'https://mongodb-mms-prod-build-server.s3.amazonaws.com/openapi/changelog'; const atlasAdminDevChangelogS3Prefix = 'https://mongodb-mms-build-server.s3.amazonaws.com/openapi/changelog'; @@ -112,6 +112,4 @@ const createOpenAPIChangelogNode = async ({ createNode, createNodeId, createCont } }; -module.exports = { - createOpenAPIChangelogNode, -}; +export { createOpenAPIChangelogNode }; diff --git a/plugins/utils/products.js b/plugins/utils/products.js index 60f30bdea..423c68e5e 100644 --- a/plugins/utils/products.js +++ b/plugins/utils/products.js @@ -1,4 +1,4 @@ -const { baseUrl } = require('../../src/utils/base-url'); +import { baseUrl } from '../../src/utils/base-url.js'; const createProductNodes = async ({ db, createNode, createNodeId, createContentDigest }) => { // Get all MongoDB products for the sidenav @@ -20,6 +20,4 @@ const createProductNodes = async ({ db, createNode, createNodeId, createContentD }); }; -module.exports = { - createProductNodes, -}; +export { createProductNodes }; diff --git a/src/build-constants.js b/src/build-constants.js index 8d62e4e83..c4172f91b 100644 --- a/src/build-constants.js +++ b/src/build-constants.js @@ -1,6 +1,6 @@ -module.exports = { - DOCUMENTS_COLLECTION: 'documents', - ASSETS_COLLECTION: 'assets', - METADATA_COLLECTION: 'metadata', - SNOOTY_REALM_APP_ID: 'snooty-koueq', -}; +const DOCUMENTS_COLLECTION = 'documents'; +const ASSETS_COLLECTION = 'assets'; +const METADATA_COLLECTION = 'metadata'; +const SNOOTY_REALM_APP_ID = 'snooty-koueq'; + +export { DOCUMENTS_COLLECTION, ASSETS_COLLECTION, METADATA_COLLECTION, SNOOTY_REALM_APP_ID }; diff --git a/src/components/OpenAPIChangelog/utils/filterHiddenChanges.js b/src/components/OpenAPIChangelog/utils/filterHiddenChanges.js index f4e1b4656..83c244754 100644 --- a/src/components/OpenAPIChangelog/utils/filterHiddenChanges.js +++ b/src/components/OpenAPIChangelog/utils/filterHiddenChanges.js @@ -43,4 +43,4 @@ const hideDiffChanges = (diffData) => { return updatedDiffData.filter((path) => path.changes?.length); }; -module.exports = { hideChanges, hideDiffChanges }; +export { hideChanges, hideDiffChanges }; diff --git a/src/init/DocumentDatabase.js b/src/init/DocumentDatabase.js index 67df17a30..391cac4c4 100644 --- a/src/init/DocumentDatabase.js +++ b/src/init/DocumentDatabase.js @@ -1,9 +1,9 @@ -const AdmZip = require('adm-zip'); -const BSON = require('bson'); -const { initRealm } = require('../utils/setup/init-realm'); -const { DOCUMENTS_COLLECTION, METADATA_COLLECTION, ASSETS_COLLECTION } = require('../build-constants'); -const { manifestMetadata, siteMetadata } = require('../utils/site-metadata'); -const { constructBuildFilter } = require('../utils/setup/construct-build-filter'); +import AdmZip from 'adm-zip'; +import BSON from 'bson'; +import { initRealm } from '../utils/setup/init-realm.js'; +import { DOCUMENTS_COLLECTION, METADATA_COLLECTION, ASSETS_COLLECTION } from '../build-constants.js'; +import { manifestMetadata, siteMetadata } from '../utils/site-metadata.js'; +import { constructBuildFilter } from '../utils/setup/construct-build-filter.js'; const DB = siteMetadata.database; const buildFilter = constructBuildFilter(siteMetadata); @@ -126,5 +126,7 @@ class RealmDocumentDatabase { } } -exports.manifestDocumentDatabase = new ManifestDocumentDatabase(process.env.GATSBY_MANIFEST_PATH); -exports.realmDocumentDatabase = new RealmDocumentDatabase(); +const manifestDocumentDatabase = new ManifestDocumentDatabase(process.env.GATSBY_MANIFEST_PATH); +const realmDocumentDatabase = new RealmDocumentDatabase(); + +export { manifestDocumentDatabase, realmDocumentDatabase }; diff --git a/src/utils/assert-trailing-slash.js b/src/utils/assert-trailing-slash.js index b7739b6a4..3fb91ec37 100644 --- a/src/utils/assert-trailing-slash.js +++ b/src/utils/assert-trailing-slash.js @@ -5,4 +5,4 @@ const assertTrailingSlash = (url) => { return `${url}/`; }; -module.exports.assertTrailingSlash = assertTrailingSlash; +export { assertTrailingSlash }; diff --git a/src/utils/base-url.js b/src/utils/base-url.js index 726e0b471..e29cce32a 100644 --- a/src/utils/base-url.js +++ b/src/utils/base-url.js @@ -1,4 +1,4 @@ -const { assertTrailingSlash } = require('./assert-trailing-slash'); +import { assertTrailingSlash } from './assert-trailing-slash.js'; const DOTCOM_BASE_URL = 'https://www.mongodb.com'; const DOTCOM_BASE_PREFIX = `docs`; @@ -59,4 +59,4 @@ const baseUrl = (url = DOTCOM_BASE_URL, options = {}) => { return assertTrailingSlash(needsProtocol ? baseUrl.toString() : baseUrl.toString().split('//')[1]); }; -module.exports = { baseUrl, DOTCOM_BASE_PREFIX, DOTCOM_BASE_URL }; +export { baseUrl, DOTCOM_BASE_PREFIX, DOTCOM_BASE_URL }; diff --git a/src/utils/generate-path-prefix.js b/src/utils/generate-path-prefix.js index 6eda621f4..00e42a727 100644 --- a/src/utils/generate-path-prefix.js +++ b/src/utils/generate-path-prefix.js @@ -1,4 +1,4 @@ -const { normalizePath } = require('./normalize-path'); +import { normalizePath } from './normalize-path.js'; const generatePathPrefix = ( { commitHash, parserBranch, patchId, pathPrefix, project: parserProject, snootyBranch, user }, @@ -32,6 +32,4 @@ const generatePathPrefix = ( return normalizePath(path); }; -// TODO: switch to ES6 export syntax if Gatsby implements support for ES6 module imports -// https://github.com/gatsbyjs/gatsby/issues/7810 -module.exports.generatePathPrefix = generatePathPrefix; +export { generatePathPrefix }; diff --git a/src/utils/get-nested-value.js b/src/utils/get-nested-value.js index 9b703e7ee..fd47f92fd 100644 --- a/src/utils/get-nested-value.js +++ b/src/utils/get-nested-value.js @@ -9,6 +9,4 @@ const getNestedValue = (p, o) => { return p.reduce((xs, x) => (xs && xs[x] ? xs[x] : undefined), o); }; -// TODO: switch to ES6 export syntax if Gatsby implements support for ES6 module imports -// https://github.com/gatsbyjs/gatsby/issues/7810 -module.exports.getNestedValue = getNestedValue; +export { getNestedValue }; diff --git a/src/utils/get-page-slug.js b/src/utils/get-page-slug.js index ad2ca13bc..ad54cbd31 100644 --- a/src/utils/get-page-slug.js +++ b/src/utils/get-page-slug.js @@ -3,4 +3,4 @@ const getPageSlug = (page) => { return page === 'index' ? '/' : page; }; -module.exports.getPageSlug = getPageSlug; +export { getPageSlug }; diff --git a/src/utils/get-plaintext.js b/src/utils/get-plaintext.js index fd828fccc..2a4dfcc13 100644 --- a/src/utils/get-plaintext.js +++ b/src/utils/get-plaintext.js @@ -15,4 +15,4 @@ const getPlaintext = (nodeArray) => { return nodeArray && nodeArray.length > 0 ? nodeArray.reduce(extractText, '') : ''; }; -module.exports = { getPlaintext }; +export { getPlaintext }; diff --git a/src/utils/is-gatsby-preview.js b/src/utils/is-gatsby-preview.js index f6e1c7b65..610e10335 100644 --- a/src/utils/is-gatsby-preview.js +++ b/src/utils/is-gatsby-preview.js @@ -3,4 +3,4 @@ */ const isGatsbyPreview = () => process.env.GATSBY_IS_PREVIEW === 'true'; -module.exports = { isGatsbyPreview }; +export { isGatsbyPreview }; diff --git a/src/utils/normalize-path.js b/src/utils/normalize-path.js index f1a4307f1..9ad1fbcf1 100644 --- a/src/utils/normalize-path.js +++ b/src/utils/normalize-path.js @@ -1,4 +1,4 @@ // Remove duplicate slashes in path string const normalizePath = (path) => path.replace(/\/+/g, `/`); -module.exports.normalizePath = normalizePath; +export { normalizePath }; diff --git a/src/utils/remove-nested-value.js b/src/utils/remove-nested-value.js index 6ee71cced..7f5d8a5d2 100644 --- a/src/utils/remove-nested-value.js +++ b/src/utils/remove-nested-value.js @@ -22,4 +22,4 @@ const removeNestedValue = (target, traversalKey, arr) => { }); }; -module.exports.removeNestedValue = removeNestedValue; +export { removeNestedValue }; diff --git a/src/utils/setup/construct-build-filter.js b/src/utils/setup/construct-build-filter.js index 59c601c21..ceb4a9277 100644 --- a/src/utils/setup/construct-build-filter.js +++ b/src/utils/setup/construct-build-filter.js @@ -1,4 +1,4 @@ -const { constructPageIdPrefix } = require('./construct-page-id-prefix'); +import { constructPageIdPrefix } from './construct-page-id-prefix.js'; // Returns the query to be used by our Stitch/Realm function to fetch a site's documents const constructBuildFilter = ({ commitHash, patchId, ...rest }) => { @@ -10,4 +10,4 @@ const constructBuildFilter = ({ commitHash, patchId, ...rest }) => { }; }; -module.exports = { constructBuildFilter }; +export { constructBuildFilter }; diff --git a/src/utils/setup/construct-page-id-prefix.js b/src/utils/setup/construct-page-id-prefix.js index 2537fe7c4..bd4f6ea81 100644 --- a/src/utils/setup/construct-page-id-prefix.js +++ b/src/utils/setup/construct-page-id-prefix.js @@ -1,4 +1,4 @@ // Concatenates a site prefix to return a page id const constructPageIdPrefix = ({ project, parserUser, parserBranch }) => `${project}/${parserUser}/${parserBranch}`; -module.exports = { constructPageIdPrefix }; +export { constructPageIdPrefix }; diff --git a/src/utils/setup/fetch-manifest-metadata.js b/src/utils/setup/fetch-manifest-metadata.js index 2c5457bf8..e7b501f99 100644 --- a/src/utils/setup/fetch-manifest-metadata.js +++ b/src/utils/setup/fetch-manifest-metadata.js @@ -1,5 +1,5 @@ -const AdmZip = require('adm-zip'); -const BSON = require('bson'); +import AdmZip from 'adm-zip'; +import BSON from 'bson'; // Returns the metadata from the manifest file if provided const fetchManifestMetadata = () => { @@ -16,4 +16,4 @@ const fetchManifestMetadata = () => { return metadata; }; -module.exports = { fetchManifestMetadata }; +export { fetchManifestMetadata }; diff --git a/src/utils/setup/init-realm.js b/src/utils/setup/init-realm.js index cd6de65d6..bebc8f1ab 100644 --- a/src/utils/setup/init-realm.js +++ b/src/utils/setup/init-realm.js @@ -1,5 +1,5 @@ -const Realm = require('realm-web'); -const { SNOOTY_REALM_APP_ID } = require('../../build-constants'); +import Realm from 'realm-web'; +import { SNOOTY_REALM_APP_ID } from '../../build-constants.js'; const initRealm = async () => { // Returns an instance of an app. @@ -10,4 +10,4 @@ const initRealm = async () => { return anonymous; }; -module.exports = { initRealm }; +export { initRealm }; diff --git a/src/utils/setup/save-asset-files.js b/src/utils/setup/save-asset-files.js index 17d2b956f..df02eb7b4 100644 --- a/src/utils/setup/save-asset-files.js +++ b/src/utils/setup/save-asset-files.js @@ -1,5 +1,5 @@ -const fs = require('fs').promises; -const path = require('path'); +import fs from 'node:fs/promises'; +import path from 'path'; const saveFile = async (file, data) => { await fs.mkdir(path.join('public', path.dirname(file)), { @@ -37,4 +37,4 @@ const saveStaticFiles = async (staticFiles) => { ); }; -module.exports = { saveAssetFiles, saveStaticFiles, saveFile }; +export { saveAssetFiles, saveStaticFiles, saveFile }; diff --git a/src/utils/setup/transform-breadcrumbs.js b/src/utils/setup/transform-breadcrumbs.js index e7dee4b06..a56a8969a 100644 --- a/src/utils/setup/transform-breadcrumbs.js +++ b/src/utils/setup/transform-breadcrumbs.js @@ -1,4 +1,4 @@ -const { getPlaintext } = require('../get-plaintext'); +import { getPlaintext } from '../get-plaintext.js'; const transformBreadcrumbs = (breadcrumbs, slugToTitle) => { Object.entries(breadcrumbs).forEach(([slug, breadcrumbList]) => { @@ -13,4 +13,4 @@ const transformBreadcrumbs = (breadcrumbs, slugToTitle) => { }); }; -module.exports = { transformBreadcrumbs }; +export { transformBreadcrumbs }; diff --git a/src/utils/setup/validate-env-variables.js b/src/utils/setup/validate-env-variables.js index 56c11f3a1..edb3a5a27 100644 --- a/src/utils/setup/validate-env-variables.js +++ b/src/utils/setup/validate-env-variables.js @@ -1,4 +1,4 @@ -const fs = require('fs'); +import fs from 'fs'; // env variables for building site along with use in front-end // https://www.gatsbyjs.org/docs/environment-variables/#defining-environment-variables @@ -100,4 +100,4 @@ const replaceIncorrectEnvVars = (incorrectEnvVars, envVars) => { } }; -module.exports.validateEnvVariables = validateEnvVariables; +export { validateEnvVariables }; diff --git a/src/utils/site-metadata.js b/src/utils/site-metadata.js index 6811620a5..e49abc6df 100644 --- a/src/utils/site-metadata.js +++ b/src/utils/site-metadata.js @@ -1,12 +1,13 @@ -const { execSync } = require('child_process'); -const userInfo = require('os').userInfo; -const { fetchManifestMetadata } = require('../utils/setup/fetch-manifest-metadata'); -const { DOTCOM_BASE_URL } = require('./base-url'); +import { execSync } from 'child_process'; +import { userInfo } from 'os'; +import dotenv from 'dotenv'; +import { fetchManifestMetadata } from '../utils/setup/fetch-manifest-metadata.js'; +import { DOTCOM_BASE_URL } from './base-url.js'; // loads vars from the .env file into process.env object const runningEnv = process.env.NODE_ENV || 'production'; -require('dotenv').config({ +dotenv.config({ path: `.env.${runningEnv}`, }); @@ -75,5 +76,4 @@ const siteMetadata = { manifestPath: process.env.GATSBY_MANIFEST_PATH, }; -module.exports.siteMetadata = siteMetadata; -module.exports.manifestMetadata = manifestMetadata; +export { siteMetadata, manifestMetadata }; From 091ed5921e6072dc46d4e86cbb4fc79c9fdc88f9 Mon Sep 17 00:00:00 2001 From: Maya Raman Date: Tue, 28 Nov 2023 16:04:04 -0500 Subject: [PATCH 03/13] npm run build works, but has a warning --- gatsby-config.mjs | 6 ++--- package.json | 1 - .../gatsby-source-snooty-prod/gatsby-node.mjs | 24 +++++++++---------- plugins/utils/{openapi.js => openapi.mjs} | 2 +- plugins/utils/{products.js => products.mjs} | 2 +- ...build-constants.js => build-constants.mjs} | 0 ...ddenChanges.js => filterHiddenChanges.mjs} | 0 ...cumentDatabase.js => DocumentDatabase.mjs} | 8 +++---- ...ing-slash.js => assert-trailing-slash.mjs} | 0 src/utils/{base-url.js => base-url.mjs} | 2 +- ...ath-prefix.js => generate-path-prefix.mjs} | 2 +- ...t-nested-value.js => get-nested-value.mjs} | 0 .../{get-page-slug.js => get-page-slug.mjs} | 0 .../{get-plaintext.js => get-plaintext.mjs} | 0 ...atsby-preview.js => is-gatsby-preview.mjs} | 0 .../{normalize-path.js => normalize-path.mjs} | 0 ...ested-value.js => remove-nested-value.mjs} | 0 ...d-filter.js => construct-build-filter.mjs} | 2 +- ...prefix.js => construct-page-id-prefix.mjs} | 0 ...etadata.js => fetch-manifest-metadata.mjs} | 0 .../setup/{init-realm.js => init-realm.mjs} | 2 +- ...ve-asset-files.js => save-asset-files.mjs} | 0 ...eadcrumbs.js => transform-breadcrumbs.mjs} | 2 +- ...ariables.js => validate-env-variables.mjs} | 0 .../{site-metadata.js => site-metadata.mjs} | 4 ++-- 25 files changed, 28 insertions(+), 29 deletions(-) rename plugins/utils/{openapi.js => openapi.mjs} (98%) rename plugins/utils/{products.js => products.mjs} (91%) rename src/{build-constants.js => build-constants.mjs} (100%) rename src/components/OpenAPIChangelog/utils/{filterHiddenChanges.js => filterHiddenChanges.mjs} (100%) rename src/init/{DocumentDatabase.js => DocumentDatabase.mjs} (96%) rename src/utils/{assert-trailing-slash.js => assert-trailing-slash.mjs} (100%) rename src/utils/{base-url.js => base-url.mjs} (97%) rename src/utils/{generate-path-prefix.js => generate-path-prefix.mjs} (96%) rename src/utils/{get-nested-value.js => get-nested-value.mjs} (100%) rename src/utils/{get-page-slug.js => get-page-slug.mjs} (100%) rename src/utils/{get-plaintext.js => get-plaintext.mjs} (100%) rename src/utils/{is-gatsby-preview.js => is-gatsby-preview.mjs} (100%) rename src/utils/{normalize-path.js => normalize-path.mjs} (100%) rename src/utils/{remove-nested-value.js => remove-nested-value.mjs} (100%) rename src/utils/setup/{construct-build-filter.js => construct-build-filter.mjs} (98%) rename src/utils/setup/{construct-page-id-prefix.js => construct-page-id-prefix.mjs} (100%) rename src/utils/setup/{fetch-manifest-metadata.js => fetch-manifest-metadata.mjs} (100%) rename src/utils/setup/{init-realm.js => init-realm.mjs} (85%) rename src/utils/setup/{save-asset-files.js => save-asset-files.mjs} (100%) rename src/utils/setup/{transform-breadcrumbs.js => transform-breadcrumbs.mjs} (87%) rename src/utils/setup/{validate-env-variables.js => validate-env-variables.mjs} (100%) rename src/utils/{site-metadata.js => site-metadata.mjs} (93%) diff --git a/gatsby-config.mjs b/gatsby-config.mjs index 846f62c50..ed155dd20 100644 --- a/gatsby-config.mjs +++ b/gatsby-config.mjs @@ -1,7 +1,7 @@ import { createRequire } from 'module'; -import { generatePathPrefix } from './src/utils/generate-path-prefix.js'; -import { siteMetadata } from './src/utils/site-metadata.js'; -import { isGatsbyPreview } from './src/utils/is-gatsby-preview.js'; +import { generatePathPrefix } from './src/utils/generate-path-prefix.mjs'; +import { siteMetadata } from './src/utils/site-metadata.mjs'; +import { isGatsbyPreview } from './src/utils/is-gatsby-preview.mjs'; const isPreview = isGatsbyPreview(); const pathPrefix = !isPreview ? generatePathPrefix(siteMetadata) : undefined; diff --git a/package.json b/package.json index c9252d662..5da746b8c 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,6 @@ { "name": "snooty", "version": "0.15.1", - "type": "module", "repository": "github:mongodb/snooty", "engines": { "node": "^18", diff --git a/plugins/gatsby-source-snooty-prod/gatsby-node.mjs b/plugins/gatsby-source-snooty-prod/gatsby-node.mjs index 57b75530d..2b7cfc02b 100644 --- a/plugins/gatsby-source-snooty-prod/gatsby-node.mjs +++ b/plugins/gatsby-source-snooty-prod/gatsby-node.mjs @@ -2,18 +2,18 @@ import path from 'path'; import { dirname } from 'path'; import { fileURLToPath } from 'url'; import { createRequire } from 'module'; -import { transformBreadcrumbs } from '../../src/utils/setup/transform-breadcrumbs.js'; -import { saveAssetFiles, saveStaticFiles } from '../../src/utils/setup/save-asset-files.js'; -import { validateEnvVariables } from '../../src/utils/setup/validate-env-variables.js'; -import { getNestedValue } from '../../src/utils/get-nested-value.js'; -import { removeNestedValue } from '../../src/utils/remove-nested-value.js'; -import { getPageSlug } from '../../src/utils/get-page-slug.js'; -import { manifestMetadata, siteMetadata } from '../../src/utils/site-metadata.js'; -import { assertTrailingSlash } from '../../src/utils/assert-trailing-slash.js'; -import { constructPageIdPrefix } from '../../src/utils/setup/construct-page-id-prefix.js'; -import { manifestDocumentDatabase, realmDocumentDatabase } from '../../src/init/DocumentDatabase.js'; -import { createOpenAPIChangelogNode } from '../utils/openapi.js'; -import { createProductNodes } from '../utils/products.js'; +import { transformBreadcrumbs } from '../../src/utils/setup/transform-breadcrumbs.mjs'; +import { saveAssetFiles, saveStaticFiles } from '../../src/utils/setup/save-asset-files.mjs'; +import { validateEnvVariables } from '../../src/utils/setup/validate-env-variables.mjs'; +import { getNestedValue } from '../../src/utils/get-nested-value.mjs'; +import { removeNestedValue } from '../../src/utils/remove-nested-value.mjs'; +import { getPageSlug } from '../../src/utils/get-page-slug.mjs'; +import { manifestMetadata, siteMetadata } from '../../src/utils/site-metadata.mjs'; +import { assertTrailingSlash } from '../../src/utils/assert-trailing-slash.mjs'; +import { constructPageIdPrefix } from '../../src/utils/setup/construct-page-id-prefix.mjs'; +import { manifestDocumentDatabase, realmDocumentDatabase } from '../../src/init/DocumentDatabase.mjs'; +import { createOpenAPIChangelogNode } from '../utils/openapi.mjs'; +import { createProductNodes } from '../utils/products.mjs'; // different types of references const PAGES = []; diff --git a/plugins/utils/openapi.js b/plugins/utils/openapi.mjs similarity index 98% rename from plugins/utils/openapi.js rename to plugins/utils/openapi.mjs index 90eaa4d56..90ae8bee5 100644 --- a/plugins/utils/openapi.js +++ b/plugins/utils/openapi.mjs @@ -1,4 +1,4 @@ -import { hideChanges, hideDiffChanges } from '../../src/components/OpenAPIChangelog/utils/filterHiddenChanges.js'; +import { hideChanges, hideDiffChanges } from '../../src/components/OpenAPIChangelog/utils/filterHiddenChanges.mjs'; const atlasAdminProdChangelogS3Prefix = 'https://mongodb-mms-prod-build-server.s3.amazonaws.com/openapi/changelog'; const atlasAdminDevChangelogS3Prefix = 'https://mongodb-mms-build-server.s3.amazonaws.com/openapi/changelog'; diff --git a/plugins/utils/products.js b/plugins/utils/products.mjs similarity index 91% rename from plugins/utils/products.js rename to plugins/utils/products.mjs index 423c68e5e..8c4b542aa 100644 --- a/plugins/utils/products.js +++ b/plugins/utils/products.mjs @@ -1,4 +1,4 @@ -import { baseUrl } from '../../src/utils/base-url.js'; +import { baseUrl } from '../../src/utils/base-url.mjs'; const createProductNodes = async ({ db, createNode, createNodeId, createContentDigest }) => { // Get all MongoDB products for the sidenav diff --git a/src/build-constants.js b/src/build-constants.mjs similarity index 100% rename from src/build-constants.js rename to src/build-constants.mjs diff --git a/src/components/OpenAPIChangelog/utils/filterHiddenChanges.js b/src/components/OpenAPIChangelog/utils/filterHiddenChanges.mjs similarity index 100% rename from src/components/OpenAPIChangelog/utils/filterHiddenChanges.js rename to src/components/OpenAPIChangelog/utils/filterHiddenChanges.mjs diff --git a/src/init/DocumentDatabase.js b/src/init/DocumentDatabase.mjs similarity index 96% rename from src/init/DocumentDatabase.js rename to src/init/DocumentDatabase.mjs index 391cac4c4..77d92cad4 100644 --- a/src/init/DocumentDatabase.js +++ b/src/init/DocumentDatabase.mjs @@ -1,9 +1,9 @@ import AdmZip from 'adm-zip'; import BSON from 'bson'; -import { initRealm } from '../utils/setup/init-realm.js'; -import { DOCUMENTS_COLLECTION, METADATA_COLLECTION, ASSETS_COLLECTION } from '../build-constants.js'; -import { manifestMetadata, siteMetadata } from '../utils/site-metadata.js'; -import { constructBuildFilter } from '../utils/setup/construct-build-filter.js'; +import { initRealm } from '../utils/setup/init-realm.mjs'; +import { DOCUMENTS_COLLECTION, METADATA_COLLECTION, ASSETS_COLLECTION } from '../build-constants.mjs'; +import { manifestMetadata, siteMetadata } from '../utils/site-metadata.mjs'; +import { constructBuildFilter } from '../utils/setup/construct-build-filter.mjs'; const DB = siteMetadata.database; const buildFilter = constructBuildFilter(siteMetadata); diff --git a/src/utils/assert-trailing-slash.js b/src/utils/assert-trailing-slash.mjs similarity index 100% rename from src/utils/assert-trailing-slash.js rename to src/utils/assert-trailing-slash.mjs diff --git a/src/utils/base-url.js b/src/utils/base-url.mjs similarity index 97% rename from src/utils/base-url.js rename to src/utils/base-url.mjs index e29cce32a..38e2db523 100644 --- a/src/utils/base-url.js +++ b/src/utils/base-url.mjs @@ -1,4 +1,4 @@ -import { assertTrailingSlash } from './assert-trailing-slash.js'; +import { assertTrailingSlash } from './assert-trailing-slash.mjs'; const DOTCOM_BASE_URL = 'https://www.mongodb.com'; const DOTCOM_BASE_PREFIX = `docs`; diff --git a/src/utils/generate-path-prefix.js b/src/utils/generate-path-prefix.mjs similarity index 96% rename from src/utils/generate-path-prefix.js rename to src/utils/generate-path-prefix.mjs index 00e42a727..f340905fc 100644 --- a/src/utils/generate-path-prefix.js +++ b/src/utils/generate-path-prefix.mjs @@ -1,4 +1,4 @@ -import { normalizePath } from './normalize-path.js'; +import { normalizePath } from './normalize-path.mjs'; const generatePathPrefix = ( { commitHash, parserBranch, patchId, pathPrefix, project: parserProject, snootyBranch, user }, diff --git a/src/utils/get-nested-value.js b/src/utils/get-nested-value.mjs similarity index 100% rename from src/utils/get-nested-value.js rename to src/utils/get-nested-value.mjs diff --git a/src/utils/get-page-slug.js b/src/utils/get-page-slug.mjs similarity index 100% rename from src/utils/get-page-slug.js rename to src/utils/get-page-slug.mjs diff --git a/src/utils/get-plaintext.js b/src/utils/get-plaintext.mjs similarity index 100% rename from src/utils/get-plaintext.js rename to src/utils/get-plaintext.mjs diff --git a/src/utils/is-gatsby-preview.js b/src/utils/is-gatsby-preview.mjs similarity index 100% rename from src/utils/is-gatsby-preview.js rename to src/utils/is-gatsby-preview.mjs diff --git a/src/utils/normalize-path.js b/src/utils/normalize-path.mjs similarity index 100% rename from src/utils/normalize-path.js rename to src/utils/normalize-path.mjs diff --git a/src/utils/remove-nested-value.js b/src/utils/remove-nested-value.mjs similarity index 100% rename from src/utils/remove-nested-value.js rename to src/utils/remove-nested-value.mjs diff --git a/src/utils/setup/construct-build-filter.js b/src/utils/setup/construct-build-filter.mjs similarity index 98% rename from src/utils/setup/construct-build-filter.js rename to src/utils/setup/construct-build-filter.mjs index ceb4a9277..b26da10ee 100644 --- a/src/utils/setup/construct-build-filter.js +++ b/src/utils/setup/construct-build-filter.mjs @@ -1,4 +1,4 @@ -import { constructPageIdPrefix } from './construct-page-id-prefix.js'; +import { constructPageIdPrefix } from './construct-page-id-prefix.mjs'; // Returns the query to be used by our Stitch/Realm function to fetch a site's documents const constructBuildFilter = ({ commitHash, patchId, ...rest }) => { diff --git a/src/utils/setup/construct-page-id-prefix.js b/src/utils/setup/construct-page-id-prefix.mjs similarity index 100% rename from src/utils/setup/construct-page-id-prefix.js rename to src/utils/setup/construct-page-id-prefix.mjs diff --git a/src/utils/setup/fetch-manifest-metadata.js b/src/utils/setup/fetch-manifest-metadata.mjs similarity index 100% rename from src/utils/setup/fetch-manifest-metadata.js rename to src/utils/setup/fetch-manifest-metadata.mjs diff --git a/src/utils/setup/init-realm.js b/src/utils/setup/init-realm.mjs similarity index 85% rename from src/utils/setup/init-realm.js rename to src/utils/setup/init-realm.mjs index bebc8f1ab..fb0d33026 100644 --- a/src/utils/setup/init-realm.js +++ b/src/utils/setup/init-realm.mjs @@ -1,5 +1,5 @@ import Realm from 'realm-web'; -import { SNOOTY_REALM_APP_ID } from '../../build-constants.js'; +import { SNOOTY_REALM_APP_ID } from '../../build-constants.mjs'; const initRealm = async () => { // Returns an instance of an app. diff --git a/src/utils/setup/save-asset-files.js b/src/utils/setup/save-asset-files.mjs similarity index 100% rename from src/utils/setup/save-asset-files.js rename to src/utils/setup/save-asset-files.mjs diff --git a/src/utils/setup/transform-breadcrumbs.js b/src/utils/setup/transform-breadcrumbs.mjs similarity index 87% rename from src/utils/setup/transform-breadcrumbs.js rename to src/utils/setup/transform-breadcrumbs.mjs index a56a8969a..14e3cf763 100644 --- a/src/utils/setup/transform-breadcrumbs.js +++ b/src/utils/setup/transform-breadcrumbs.mjs @@ -1,4 +1,4 @@ -import { getPlaintext } from '../get-plaintext.js'; +import { getPlaintext } from '../get-plaintext.mjs'; const transformBreadcrumbs = (breadcrumbs, slugToTitle) => { Object.entries(breadcrumbs).forEach(([slug, breadcrumbList]) => { diff --git a/src/utils/setup/validate-env-variables.js b/src/utils/setup/validate-env-variables.mjs similarity index 100% rename from src/utils/setup/validate-env-variables.js rename to src/utils/setup/validate-env-variables.mjs diff --git a/src/utils/site-metadata.js b/src/utils/site-metadata.mjs similarity index 93% rename from src/utils/site-metadata.js rename to src/utils/site-metadata.mjs index e49abc6df..7b1c74ad3 100644 --- a/src/utils/site-metadata.js +++ b/src/utils/site-metadata.mjs @@ -1,8 +1,8 @@ import { execSync } from 'child_process'; import { userInfo } from 'os'; import dotenv from 'dotenv'; -import { fetchManifestMetadata } from '../utils/setup/fetch-manifest-metadata.js'; -import { DOTCOM_BASE_URL } from './base-url.js'; +import { fetchManifestMetadata } from './setup/fetch-manifest-metadata.mjs'; +import { DOTCOM_BASE_URL } from './base-url.mjs'; // loads vars from the .env file into process.env object const runningEnv = process.env.NODE_ENV || 'production'; From 3a92218a6ca133e821d2d7c846becfaf32284bc9 Mon Sep 17 00:00:00 2001 From: Maya Raman Date: Tue, 28 Nov 2023 16:23:51 -0500 Subject: [PATCH 04/13] adding gatsby-source-snooty-preview/gatsby-node.mjs just in case --- .../gatsby-node.mjs | 8 +- .../other-things-to-source.mjs | 14 ++++ .../utils/kanopy-auth.mjs | 75 +++++++++++++++++++ .../utils/post-build.mjs | 55 ++++++++++++++ 4 files changed, 148 insertions(+), 4 deletions(-) create mode 100644 plugins/gatsby-source-snooty-preview/other-things-to-source.mjs create mode 100644 plugins/gatsby-source-snooty-preview/utils/kanopy-auth.mjs create mode 100644 plugins/gatsby-source-snooty-preview/utils/post-build.mjs diff --git a/plugins/gatsby-source-snooty-preview/gatsby-node.mjs b/plugins/gatsby-source-snooty-preview/gatsby-node.mjs index 2254230a5..141586676 100644 --- a/plugins/gatsby-source-snooty-preview/gatsby-node.mjs +++ b/plugins/gatsby-source-snooty-preview/gatsby-node.mjs @@ -7,15 +7,15 @@ import { promisify } from 'util'; import got from 'got'; import { createRequire } from 'module'; import { parser } from 'stream-json/jsonl/Parser'; -import { sourceNodes } from './other-things-to-source.js'; -import { fetchClientAccessToken } from './utils/kanopy-auth.js'; -import { callPostBuildWebhook } from './utils/post-build.js'; +import { sourceNodes } from './other-things-to-source.mjs'; +import { fetchClientAccessToken } from './utils/kanopy-auth.mjs'; +import { callPostBuildWebhook } from './utils/post-build.mjs'; import { consumeData, createSnootyMetadataId, KEY_LAST_FETCHED, KEY_LAST_CLIENT_ACCESS_TOKEN, -} from './utils/data-consumer.js'; +} from './utils/data-consumer.mjs'; const pipeline = promisify(stream.pipeline); diff --git a/plugins/gatsby-source-snooty-preview/other-things-to-source.mjs b/plugins/gatsby-source-snooty-preview/other-things-to-source.mjs new file mode 100644 index 000000000..9f5e1e04c --- /dev/null +++ b/plugins/gatsby-source-snooty-preview/other-things-to-source.mjs @@ -0,0 +1,14 @@ +import { siteMetadata } from '../../src/utils/site-metadata.mjs'; +import { realmDocumentDatabase } from '../../src/init/DocumentDatabase.mjs'; +import { createOpenAPIChangelogNode } from '../utils/openapi.mjs'; +import { createProductNodes } from '../utils/products.mjs'; + +// Sources nodes for the preview plugin that are not directly related to data +// from the Snooty Data API +export const sourceNodes = async ({ hasOpenAPIChangelog, createNode, createContentDigest, createNodeId }) => { + let db = realmDocumentDatabase; + await db.connect(); + await createProductNodes({ db, createNode, createNodeId, createContentDigest }); + if (hasOpenAPIChangelog) + await createOpenAPIChangelogNode({ createNode, createNodeId, createContentDigest, siteMetadata, db }); +}; diff --git a/plugins/gatsby-source-snooty-preview/utils/kanopy-auth.mjs b/plugins/gatsby-source-snooty-preview/utils/kanopy-auth.mjs new file mode 100644 index 000000000..823089c9f --- /dev/null +++ b/plugins/gatsby-source-snooty-preview/utils/kanopy-auth.mjs @@ -0,0 +1,75 @@ +/** + * Checks if the configuration property exists, and throws an error otherwise. + * @param configProp + * @param configType + */ +const validateConfigType = (configProp, configType) => { + if (!configProp) { + throw new Error(`Missing ${configType} for Snooty Data API access`); + } +}; + +/** + * Generates the authZ token needed for requesting an access token to Kanopy. + */ +const getClientCredentialsHeader = () => { + const clientId = process.env.OAUTH_CLIENT_ID; + validateConfigType(clientId, 'client ID'); + const clientSecret = process.env.OAUTH_CLIENT_SECRET; + validateConfigType(clientSecret, 'client secret'); + return Buffer.from(`${clientId}:${clientSecret}`, 'utf-8').toString('base64'); +}; + +/** + * Generates a new access token to allow for authentication against Kanopy services. + */ +const generateNewAccessToken = async () => { + const grantType = process.env.OAUTH_GRANT_TYPE; + validateConfigType(grantType, 'grant type'); + const scope = process.env.OAUTH_SCOPE; + validateConfigType(scope, 'scope'); + const authUrl = process.env.OAUTH_TOKEN_AUTH_URL; + validateConfigType(authUrl, 'auth token url'); + + // Request a new access token from Kanopy's token authentication endpoint + const authRequestUrl = `${authUrl}?grant_type=${grantType}&scope=${scope}`; + const headers = { + authorization: `Basic ${getClientCredentialsHeader()}`, + accept: 'application/json', + 'Content-Type': 'application/x-www-form-urlencoded', + 'cache-control': 'no-cache', + }; + const res = await fetch(authRequestUrl, { method: 'POST', headers }); + if (!res.ok) { + throw new Error('Error trying to request new access token'); + } + + const data = await res.json(); + const token = data['access_token']; + if (!token) { + throw new Error('Could not find new access token'); + } + + return token; +}; + +/** + * Returns a valid client access token that can be used for machine-machine communication + * between a client and a service hosted on Kanopy. + * See: https://kanopy.corp.mongodb.com/docs/development/authentication_and_authorization/ + * @param prevToken + */ +const fetchClientAccessToken = async (prevToken) => { + if (!prevToken) { + return generateNewAccessToken(); + } + // Decoded value is the JSON object representation of the token string, with token's expiration date + const decodedValue = JSON.parse(Buffer.from(prevToken.split('.')[1], 'base64').toString('ascii')); + // Check if token is expired, or near expiration + if (decodedValue.exp < Date.now() / 1000) { + return generateNewAccessToken(); + } + return prevToken; +}; + +export { fetchClientAccessToken }; diff --git a/plugins/gatsby-source-snooty-preview/utils/post-build.mjs b/plugins/gatsby-source-snooty-preview/utils/post-build.mjs new file mode 100644 index 000000000..230300584 --- /dev/null +++ b/plugins/gatsby-source-snooty-preview/utils/post-build.mjs @@ -0,0 +1,55 @@ +import crypto from 'crypto'; + +/** + * Constructs a signature using the payload and Snooty's secret. The signature + * can be used to help webhooks be more confident that the caller is Snooty. + * @param {string} payloadString + */ +const constructSnootyHeader = (payloadString) => + crypto.createHmac('sha256', process.env.SNOOTY_SECRET).update(payloadString).digest('hex'); + +/** + * Calls the post-build webhook to let the Autobuilder know that the Gatsby Cloud + * build is finished. + * @param {object} webhookBody - The webhook body passed to the source plugin to + * initiate the preview build. + * @param {string} status - The status of the build, typically "completed" or "failed". + * This value should coincide with the Autobuilder's job statuses. + */ +const callPostBuildWebhook = async (webhookBody, status) => { + // Webhook body could be empty if the Gatsby Cloud site is doing a fresh build + // that was not called by the preview webhook + if (!webhookBody || !Object.keys(webhookBody).length) { + console.log('No webhookBody found. This build will not call the post-build webhook.'); + return; + } + + const supportedStatuses = ['completed', 'failed']; + if (!supportedStatuses.includes(status)) { + console.log(`Post-build webhook call does not support status "${status}".`); + return; + } + + const payload = { + ...webhookBody, + status, + }; + const body = JSON.stringify(payload); + const headers = { + 'x-snooty-signature': constructSnootyHeader(body), + }; + + console.log(`Calling post-build webhook with status "${status}".`); + const res = await fetch(process.env.AUTOBUILDER_POST_BUILD_WEBHOOK, { method: 'POST', body, headers }); + // Calling the webhook from this function should assume we are fulfilling the requirements of the call. + // Any error thrown here is definitely unexpected. + if (!res.ok) { + const errMessage = await res.text(); + throw new Error( + `There was an issue calling the Autobuilder post-build webhook. Please have the DOP team check CloudWatch logs. ${errMessage}` + ); + } + console.log('Post-build webhook was successfully called!'); +}; + +export { callPostBuildWebhook }; From af1a4ef2b2319dadc22678bc1342b837736952ee Mon Sep 17 00:00:00 2001 From: Maya Raman Date: Tue, 28 Nov 2023 17:25:01 -0500 Subject: [PATCH 05/13] adding to gatsby node stuff --- .../utils/data-consumer.mjs | 180 ++++++++++++++++++ 1 file changed, 180 insertions(+) create mode 100644 plugins/gatsby-source-snooty-preview/utils/data-consumer.mjs diff --git a/plugins/gatsby-source-snooty-preview/utils/data-consumer.mjs b/plugins/gatsby-source-snooty-preview/utils/data-consumer.mjs new file mode 100644 index 000000000..253d554c2 --- /dev/null +++ b/plugins/gatsby-source-snooty-preview/utils/data-consumer.mjs @@ -0,0 +1,180 @@ +import { transformBreadcrumbs } from '../../../src/utils/setup/transform-breadcrumbs.mjs'; +import { saveStaticFiles, saveFile } from '../../../src/utils/setup/save-asset-files.mjs'; +import { getNestedValue } from '../../../src/utils/get-nested-value.mjs'; + +const KEY_LAST_FETCHED = 'lastFetched'; +const KEY_LAST_CLIENT_ACCESS_TOKEN = 'lastClientAccessToken'; + +function createSnootyMetadataId({ branch, project, createNodeId }) { + return createNodeId(`metadata-${branch}-${project}`); +} + +// Syncs the plugin with timestamp of data being returned from the API. +const handleTimestamp = (data, { cache, clientAccessToken }) => { + cache.set(KEY_LAST_FETCHED, data); + cache.set(KEY_LAST_CLIENT_ACCESS_TOKEN, clientAccessToken); +}; + +const handleAsset = (data, { fileWritePromises }) => { + const { filenames, assetData } = data; + + // Incorrect asset format should not be acceptable + if (!filenames || !filenames.length) { + throw new Error('No filenames found for asset'); + } + if (!assetData) { + throw new Error('Missing asset data'); + } + + filenames.forEach((filePath) => { + // These promises will be resolved once all data is consumed + fileWritePromises.push(saveFile(filePath, Buffer.from(assetData, 'base64'))); + }); +}; + +const handleMetadata = async ( + data, + { createContentDigest, createNode, createNodeId, deleteNode, getNode, shouldDeleteContentNode } +) => { + const { _id, build_id, created_at, static_files: staticFiles, ...metadataMinusStatic } = data; + const { parentPaths, slugToTitle, branch, project } = metadataMinusStatic; + const nodeId = createSnootyMetadataId({ createNodeId, branch, project }); + + if (shouldDeleteContentNode) { + deleteNode(getNode(nodeId)); + return; + } + + if (parentPaths) { + transformBreadcrumbs(parentPaths, slugToTitle); + } + + // Save files in the static_files field of metadata document, including intersphinx inventories. + if (staticFiles) { + await saveStaticFiles(staticFiles); + } + + createNode({ + children: [], + id: nodeId, + internal: { + contentDigest: createContentDigest(metadataMinusStatic), + type: 'SnootyMetadata', + }, + branch, + project, + parent: null, + metadata: metadataMinusStatic, + }); +}; + +const handlePage = ( + data, + { createContentDigest, createNode, createNodeId, deleteNode, getNode, onHandlePage, shouldDeleteContentNode } +) => { + // Strip source string, in case it exists. We don't need the raw source of the AST + const { source, ...page } = data; + + const filename = getNestedValue(['filename'], page) || ''; + // There can be ASTs for included .rst files as well. We should skip these, in case + // we encounter them + if (!filename || !filename.endsWith('.txt')) { + console.warn(`Found an AST that is not for a page: ${filename}`); + return; + } + + const branch = page.page_id.split('/')[2]; + const raw_page_id = page.page_id.split('/').slice(3).join('/'); + const page_id = raw_page_id === 'index' ? '/' : `/${raw_page_id}`; + const project = page.page_id.split('/')[0]; + + const pageNodeId = createNodeId(page_id + project + branch); + const pagePathNodeId = pageNodeId + '/path'; + + if (shouldDeleteContentNode) { + deleteNode(getNode(pageNodeId)); + deleteNode(getNode(pagePathNodeId)); + return; + } + + page.page_id = page_id; + page.metadata = createSnootyMetadataId({ createNodeId, branch, project }); + page.id = pageNodeId; + page.internal = { + type: 'Page', + contentDigest: createContentDigest(page), + }; + + const pagePathNode = { + id: pagePathNodeId, + page_id, + branch, + project, + pageNodeId: page.id, + internal: { + type: 'PagePath', + contentDigest: page.internal.contentDigest, + }, + }; + + createNode(page); + createNode(pagePathNode); + + const pageTemplate = data.ast?.options?.template; + onHandlePage(pageTemplate, page_id, pageNodeId); +}; + +/** + * Handles incoming data accordingly based on its data type. Notably, this handles + * converting build data from the Snooty Data API into nodes and assets that the + * Gatsby site will need to render pages. + * @param {*} entry - A single data entry obtained from the Snooty Data API + * @param {*} options - Gatsby functions and other utilities to be used by handlers + */ +const consumeData = async ( + entry, + { actions, cache, createNodeId, createContentDigest, getNode, fileWritePromises, clientAccessToken, onHandlePage } +) => { + const { type, data } = entry; + + // Shape and format should be consistent across all data + if (!type) { + throw new Error('Data entry is missing data type'); + } + if (!data) { + throw new Error('Data entry is missing data'); + } + + const shouldDeleteContentNode = data.deleted; + const { createNode, deleteNode } = actions; + + if (type === 'timestamp') { + handleTimestamp(data, { cache, clientAccessToken }); + } else if (type === 'asset') { + handleAsset(data, { fileWritePromises }); + } else if (type === 'metadata') { + await handleMetadata(data, { + createContentDigest, + createNode, + createNodeId, + deleteNode, + getNode, + shouldDeleteContentNode, + }); + } else if (type === 'page') { + handlePage(data, { + createContentDigest, + createNode, + createNodeId, + deleteNode, + getNode, + onHandlePage, + shouldDeleteContentNode, + }); + } else { + // Shouldn't affect current builds + console.warn(`Unexpected data type: ${type}`); + } +}; + +export { consumeData, createSnootyMetadataId, KEY_LAST_FETCHED, KEY_LAST_CLIENT_ACCESS_TOKEN }; From 277bb920cc6f57469d47166422f95d187df2a4ca Mon Sep 17 00:00:00 2001 From: Maya Raman Date: Tue, 28 Nov 2023 17:26:16 -0500 Subject: [PATCH 06/13] deleting files --- .../other-things-to-source.js | 14 -- .../utils/data-consumer.js | 180 ------------------ .../utils/kanopy-auth.js | 75 -------- .../utils/post-build.js | 55 ------ 4 files changed, 324 deletions(-) delete mode 100644 plugins/gatsby-source-snooty-preview/other-things-to-source.js delete mode 100644 plugins/gatsby-source-snooty-preview/utils/data-consumer.js delete mode 100644 plugins/gatsby-source-snooty-preview/utils/kanopy-auth.js delete mode 100644 plugins/gatsby-source-snooty-preview/utils/post-build.js diff --git a/plugins/gatsby-source-snooty-preview/other-things-to-source.js b/plugins/gatsby-source-snooty-preview/other-things-to-source.js deleted file mode 100644 index 4b88bcdf5..000000000 --- a/plugins/gatsby-source-snooty-preview/other-things-to-source.js +++ /dev/null @@ -1,14 +0,0 @@ -const { siteMetadata } = require('../../src/utils/site-metadata'); -const { realmDocumentDatabase } = require('../../src/init/DocumentDatabase.js'); -const { createOpenAPIChangelogNode } = require('../utils/openapi'); -const { createProductNodes } = require('../utils/products'); - -// Sources nodes for the preview plugin that are not directly related to data -// from the Snooty Data API -exports.sourceNodes = async ({ hasOpenAPIChangelog, createNode, createContentDigest, createNodeId }) => { - let db = realmDocumentDatabase; - await db.connect(); - await createProductNodes({ db, createNode, createNodeId, createContentDigest }); - if (hasOpenAPIChangelog) - await createOpenAPIChangelogNode({ createNode, createNodeId, createContentDigest, siteMetadata, db }); -}; diff --git a/plugins/gatsby-source-snooty-preview/utils/data-consumer.js b/plugins/gatsby-source-snooty-preview/utils/data-consumer.js deleted file mode 100644 index 8ead9cb77..000000000 --- a/plugins/gatsby-source-snooty-preview/utils/data-consumer.js +++ /dev/null @@ -1,180 +0,0 @@ -const { transformBreadcrumbs } = require('../../../src/utils/setup/transform-breadcrumbs.js'); -const { saveStaticFiles, saveFile } = require('../../../src/utils/setup/save-asset-files'); -const { getNestedValue } = require('../../../src/utils/get-nested-value'); - -const KEY_LAST_FETCHED = 'lastFetched'; -const KEY_LAST_CLIENT_ACCESS_TOKEN = 'lastClientAccessToken'; - -function createSnootyMetadataId({ branch, project, createNodeId }) { - return createNodeId(`metadata-${branch}-${project}`); -} - -// Syncs the plugin with timestamp of data being returned from the API. -const handleTimestamp = (data, { cache, clientAccessToken }) => { - cache.set(KEY_LAST_FETCHED, data); - cache.set(KEY_LAST_CLIENT_ACCESS_TOKEN, clientAccessToken); -}; - -const handleAsset = (data, { fileWritePromises }) => { - const { filenames, assetData } = data; - - // Incorrect asset format should not be acceptable - if (!filenames || !filenames.length) { - throw new Error('No filenames found for asset'); - } - if (!assetData) { - throw new Error('Missing asset data'); - } - - filenames.forEach((filePath) => { - // These promises will be resolved once all data is consumed - fileWritePromises.push(saveFile(filePath, Buffer.from(assetData, 'base64'))); - }); -}; - -const handleMetadata = async ( - data, - { createContentDigest, createNode, createNodeId, deleteNode, getNode, shouldDeleteContentNode } -) => { - const { _id, build_id, created_at, static_files: staticFiles, ...metadataMinusStatic } = data; - const { parentPaths, slugToTitle, branch, project } = metadataMinusStatic; - const nodeId = createSnootyMetadataId({ createNodeId, branch, project }); - - if (shouldDeleteContentNode) { - deleteNode(getNode(nodeId)); - return; - } - - if (parentPaths) { - transformBreadcrumbs(parentPaths, slugToTitle); - } - - // Save files in the static_files field of metadata document, including intersphinx inventories. - if (staticFiles) { - await saveStaticFiles(staticFiles); - } - - createNode({ - children: [], - id: nodeId, - internal: { - contentDigest: createContentDigest(metadataMinusStatic), - type: 'SnootyMetadata', - }, - branch, - project, - parent: null, - metadata: metadataMinusStatic, - }); -}; - -const handlePage = ( - data, - { createContentDigest, createNode, createNodeId, deleteNode, getNode, onHandlePage, shouldDeleteContentNode } -) => { - // Strip source string, in case it exists. We don't need the raw source of the AST - const { source, ...page } = data; - - const filename = getNestedValue(['filename'], page) || ''; - // There can be ASTs for included .rst files as well. We should skip these, in case - // we encounter them - if (!filename || !filename.endsWith('.txt')) { - console.warn(`Found an AST that is not for a page: ${filename}`); - return; - } - - const branch = page.page_id.split('/')[2]; - const raw_page_id = page.page_id.split('/').slice(3).join('/'); - const page_id = raw_page_id === 'index' ? '/' : `/${raw_page_id}`; - const project = page.page_id.split('/')[0]; - - const pageNodeId = createNodeId(page_id + project + branch); - const pagePathNodeId = pageNodeId + '/path'; - - if (shouldDeleteContentNode) { - deleteNode(getNode(pageNodeId)); - deleteNode(getNode(pagePathNodeId)); - return; - } - - page.page_id = page_id; - page.metadata = createSnootyMetadataId({ createNodeId, branch, project }); - page.id = pageNodeId; - page.internal = { - type: 'Page', - contentDigest: createContentDigest(page), - }; - - const pagePathNode = { - id: pagePathNodeId, - page_id, - branch, - project, - pageNodeId: page.id, - internal: { - type: 'PagePath', - contentDigest: page.internal.contentDigest, - }, - }; - - createNode(page); - createNode(pagePathNode); - - const pageTemplate = data.ast?.options?.template; - onHandlePage(pageTemplate, page_id, pageNodeId); -}; - -/** - * Handles incoming data accordingly based on its data type. Notably, this handles - * converting build data from the Snooty Data API into nodes and assets that the - * Gatsby site will need to render pages. - * @param {*} entry - A single data entry obtained from the Snooty Data API - * @param {*} options - Gatsby functions and other utilities to be used by handlers - */ -const consumeData = async ( - entry, - { actions, cache, createNodeId, createContentDigest, getNode, fileWritePromises, clientAccessToken, onHandlePage } -) => { - const { type, data } = entry; - - // Shape and format should be consistent across all data - if (!type) { - throw new Error('Data entry is missing data type'); - } - if (!data) { - throw new Error('Data entry is missing data'); - } - - const shouldDeleteContentNode = data.deleted; - const { createNode, deleteNode } = actions; - - if (type === 'timestamp') { - handleTimestamp(data, { cache, clientAccessToken }); - } else if (type === 'asset') { - handleAsset(data, { fileWritePromises }); - } else if (type === 'metadata') { - await handleMetadata(data, { - createContentDigest, - createNode, - createNodeId, - deleteNode, - getNode, - shouldDeleteContentNode, - }); - } else if (type === 'page') { - handlePage(data, { - createContentDigest, - createNode, - createNodeId, - deleteNode, - getNode, - onHandlePage, - shouldDeleteContentNode, - }); - } else { - // Shouldn't affect current builds - console.warn(`Unexpected data type: ${type}`); - } -}; - -module.exports = { consumeData, createSnootyMetadataId, KEY_LAST_FETCHED, KEY_LAST_CLIENT_ACCESS_TOKEN }; diff --git a/plugins/gatsby-source-snooty-preview/utils/kanopy-auth.js b/plugins/gatsby-source-snooty-preview/utils/kanopy-auth.js deleted file mode 100644 index 51fde316c..000000000 --- a/plugins/gatsby-source-snooty-preview/utils/kanopy-auth.js +++ /dev/null @@ -1,75 +0,0 @@ -/** - * Checks if the configuration property exists, and throws an error otherwise. - * @param configProp - * @param configType - */ -const validateConfigType = (configProp, configType) => { - if (!configProp) { - throw new Error(`Missing ${configType} for Snooty Data API access`); - } -}; - -/** - * Generates the authZ token needed for requesting an access token to Kanopy. - */ -const getClientCredentialsHeader = () => { - const clientId = process.env.OAUTH_CLIENT_ID; - validateConfigType(clientId, 'client ID'); - const clientSecret = process.env.OAUTH_CLIENT_SECRET; - validateConfigType(clientSecret, 'client secret'); - return Buffer.from(`${clientId}:${clientSecret}`, 'utf-8').toString('base64'); -}; - -/** - * Generates a new access token to allow for authentication against Kanopy services. - */ -const generateNewAccessToken = async () => { - const grantType = process.env.OAUTH_GRANT_TYPE; - validateConfigType(grantType, 'grant type'); - const scope = process.env.OAUTH_SCOPE; - validateConfigType(scope, 'scope'); - const authUrl = process.env.OAUTH_TOKEN_AUTH_URL; - validateConfigType(authUrl, 'auth token url'); - - // Request a new access token from Kanopy's token authentication endpoint - const authRequestUrl = `${authUrl}?grant_type=${grantType}&scope=${scope}`; - const headers = { - authorization: `Basic ${getClientCredentialsHeader()}`, - accept: 'application/json', - 'Content-Type': 'application/x-www-form-urlencoded', - 'cache-control': 'no-cache', - }; - const res = await fetch(authRequestUrl, { method: 'POST', headers }); - if (!res.ok) { - throw new Error('Error trying to request new access token'); - } - - const data = await res.json(); - const token = data['access_token']; - if (!token) { - throw new Error('Could not find new access token'); - } - - return token; -}; - -/** - * Returns a valid client access token that can be used for machine-machine communication - * between a client and a service hosted on Kanopy. - * See: https://kanopy.corp.mongodb.com/docs/development/authentication_and_authorization/ - * @param prevToken - */ -const fetchClientAccessToken = async (prevToken) => { - if (!prevToken) { - return generateNewAccessToken(); - } - // Decoded value is the JSON object representation of the token string, with token's expiration date - const decodedValue = JSON.parse(Buffer.from(prevToken.split('.')[1], 'base64').toString('ascii')); - // Check if token is expired, or near expiration - if (decodedValue.exp < Date.now() / 1000) { - return generateNewAccessToken(); - } - return prevToken; -}; - -module.exports = { fetchClientAccessToken }; diff --git a/plugins/gatsby-source-snooty-preview/utils/post-build.js b/plugins/gatsby-source-snooty-preview/utils/post-build.js deleted file mode 100644 index 84f429290..000000000 --- a/plugins/gatsby-source-snooty-preview/utils/post-build.js +++ /dev/null @@ -1,55 +0,0 @@ -const crypto = require('crypto'); - -/** - * Constructs a signature using the payload and Snooty's secret. The signature - * can be used to help webhooks be more confident that the caller is Snooty. - * @param {string} payloadString - */ -const constructSnootyHeader = (payloadString) => - crypto.createHmac('sha256', process.env.SNOOTY_SECRET).update(payloadString).digest('hex'); - -/** - * Calls the post-build webhook to let the Autobuilder know that the Gatsby Cloud - * build is finished. - * @param {object} webhookBody - The webhook body passed to the source plugin to - * initiate the preview build. - * @param {string} status - The status of the build, typically "completed" or "failed". - * This value should coincide with the Autobuilder's job statuses. - */ -const callPostBuildWebhook = async (webhookBody, status) => { - // Webhook body could be empty if the Gatsby Cloud site is doing a fresh build - // that was not called by the preview webhook - if (!webhookBody || !Object.keys(webhookBody).length) { - console.log('No webhookBody found. This build will not call the post-build webhook.'); - return; - } - - const supportedStatuses = ['completed', 'failed']; - if (!supportedStatuses.includes(status)) { - console.log(`Post-build webhook call does not support status "${status}".`); - return; - } - - const payload = { - ...webhookBody, - status, - }; - const body = JSON.stringify(payload); - const headers = { - 'x-snooty-signature': constructSnootyHeader(body), - }; - - console.log(`Calling post-build webhook with status "${status}".`); - const res = await fetch(process.env.AUTOBUILDER_POST_BUILD_WEBHOOK, { method: 'POST', body, headers }); - // Calling the webhook from this function should assume we are fulfilling the requirements of the call. - // Any error thrown here is definitely unexpected. - if (!res.ok) { - const errMessage = await res.text(); - throw new Error( - `There was an issue calling the Autobuilder post-build webhook. Please have the DOP team check CloudWatch logs. ${errMessage}` - ); - } - console.log('Post-build webhook was successfully called!'); -}; - -module.exports = { callPostBuildWebhook }; From 96ee49d9cad2511da224ffb47be2646aa18c2957 Mon Sep 17 00:00:00 2001 From: Maya Raman Date: Tue, 28 Nov 2023 17:30:30 -0500 Subject: [PATCH 07/13] updating small file --- src/utils/get-meta-from-directive.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/utils/get-meta-from-directive.js b/src/utils/get-meta-from-directive.js index dd218ba02..bd6400d40 100644 --- a/src/utils/get-meta-from-directive.js +++ b/src/utils/get-meta-from-directive.js @@ -1,4 +1,4 @@ -const { getNestedValue } = require('./get-nested-value'); +import { getNestedValue } from './get-nested-value.mjs'; // Grabs the metadata values in question and returns them as an array // for the Meta & TwitterMeta tags @@ -33,4 +33,4 @@ const getMetaFromDirective = (type, nodes, target) => { return collectionOfMetadata; }; -module.exports.getMetaFromDirective = getMetaFromDirective; +export { getMetaFromDirective }; From 32168af05a7717561474defe4bcb02462c3470fa Mon Sep 17 00:00:00 2001 From: Maya Raman Date: Fri, 8 Dec 2023 14:47:43 -0500 Subject: [PATCH 08/13] excluding broken tests --- jest.config.js | 4 ++++ package.json | 2 +- tests/{ => tests-esm}/context/toc-context.test.js | 0 tests/{ => tests-esm}/context/version-context.test.js | 0 tests/{ => tests-esm}/unit/Admonition.test.js | 0 tests/{ => tests-esm}/unit/Banner.test.js | 0 tests/{ => tests-esm}/unit/BlockQuote.test.js | 0 tests/{ => tests-esm}/unit/BreadcrumbContainer.test.js | 0 tests/{ => tests-esm}/unit/Breadcrumbs.test.js | 0 tests/{ => tests-esm}/unit/Button.test.js | 0 tests/{ => tests-esm}/unit/CTABanner.test.js | 0 tests/{ => tests-esm}/unit/Card.test.js | 0 tests/{ => tests-esm}/unit/CardGroup.test.js | 0 tests/{ => tests-esm}/unit/CardRef.test.js | 0 tests/{ => tests-esm}/unit/ChangeList.test.js | 0 tests/{ => tests-esm}/unit/Chapter.test.js | 0 tests/{ => tests-esm}/unit/Chapters.test.js | 0 tests/{ => tests-esm}/unit/Chatbot.test.js | 0 tests/{ => tests-esm}/unit/Code.test.js | 0 tests/{ => tests-esm}/unit/CodeIO.test.js | 0 tests/{ => tests-esm}/unit/ContentsListItem.test.js | 0 tests/{ => tests-esm}/unit/DefinitionList.test.js | 0 tests/{ => tests-esm}/unit/DeprecatedVersionSelector.test.js | 0 tests/{ => tests-esm}/unit/Emphasis.test.js | 0 tests/{ => tests-esm}/unit/FeedbackWidget.test.js | 0 tests/{ => tests-esm}/unit/Field.test.js | 0 tests/{ => tests-esm}/unit/FieldList.test.js | 0 tests/{ => tests-esm}/unit/Figure.test.js | 0 tests/{ => tests-esm}/unit/Footnote.test.js | 0 tests/{ => tests-esm}/unit/FootnoteReference.test.js | 0 tests/{ => tests-esm}/unit/GuideNext.test.js | 0 tests/{ => tests-esm}/unit/GuidesLandingTree.test.js | 0 tests/{ => tests-esm}/unit/GuidesTOCTree.test.js | 0 tests/{ => tests-esm}/unit/Head.test.js | 0 tests/{ => tests-esm}/unit/Heading.test.js | 0 tests/{ => tests-esm}/unit/IA.test.js | 0 tests/{ => tests-esm}/unit/InternalPageNav.test.js | 0 tests/{ => tests-esm}/unit/Lightbox.test.js | 0 tests/{ => tests-esm}/unit/Line.test.js | 0 tests/{ => tests-esm}/unit/LineBlock.test.js | 0 tests/{ => tests-esm}/unit/Link.test.js | 0 tests/{ => tests-esm}/unit/List.test.js | 0 tests/{ => tests-esm}/unit/ListTable.test.js | 0 tests/{ => tests-esm}/unit/Literal.test.js | 0 tests/{ => tests-esm}/unit/LiteralInclude.test.js | 0 tests/{ => tests-esm}/unit/Meta.test.js | 0 tests/{ => tests-esm}/unit/OpenAPI.test.js | 0 tests/{ => tests-esm}/unit/OpenAPIChangelog.test.js | 0 tests/{ => tests-esm}/unit/Paragraph.test.js | 0 tests/{ => tests-esm}/unit/Presentation.test.js | 0 tests/{ => tests-esm}/unit/Procedure.test.js | 0 tests/{ => tests-esm}/unit/ProductsList.test.js | 0 tests/{ => tests-esm}/unit/QuizWidget.test.js | 0 tests/{ => tests-esm}/unit/Reference.test.js | 0 tests/{ => tests-esm}/unit/ReleaseSpecification.test.js | 0 tests/{ => tests-esm}/unit/Role.test.js | 0 tests/{ => tests-esm}/unit/SearchResults.test.js | 0 tests/{ => tests-esm}/unit/Section.test.js | 0 tests/{ => tests-esm}/unit/Sidenav.test.js | 0 tests/{ => tests-esm}/unit/SiteBanner.test.js | 0 tests/{ => tests-esm}/unit/Step.test.js | 0 tests/{ => tests-esm}/unit/Strong.test.js | 0 tests/{ => tests-esm}/unit/Tabs.test.js | 0 tests/{ => tests-esm}/unit/Target.test.js | 0 tests/{ => tests-esm}/unit/Text.test.js | 0 tests/{ => tests-esm}/unit/Time.test.js | 0 tests/{ => tests-esm}/unit/Toctree.test.js | 0 tests/{ => tests-esm}/unit/VersionDropdown.test.js | 0 tests/{ => tests-esm}/unit/VersionModified.test.js | 0 tests/{ => tests-esm}/unit/filterHiddenChanges.test.js | 0 .../{ => tests-esm}/unit/utils/assert-trailing-slash.test.js | 2 +- tests/{ => tests-esm}/unit/utils/base-url.test.js | 2 +- tests/{ => tests-esm}/unit/utils/generate-path-prefix.test.js | 2 +- .../unit/utils/setup/construct-build-filter.test.js | 2 +- 74 files changed, 9 insertions(+), 5 deletions(-) rename tests/{ => tests-esm}/context/toc-context.test.js (100%) rename tests/{ => tests-esm}/context/version-context.test.js (100%) rename tests/{ => tests-esm}/unit/Admonition.test.js (100%) rename tests/{ => tests-esm}/unit/Banner.test.js (100%) rename tests/{ => tests-esm}/unit/BlockQuote.test.js (100%) rename tests/{ => tests-esm}/unit/BreadcrumbContainer.test.js (100%) rename tests/{ => tests-esm}/unit/Breadcrumbs.test.js (100%) rename tests/{ => tests-esm}/unit/Button.test.js (100%) rename tests/{ => tests-esm}/unit/CTABanner.test.js (100%) rename tests/{ => tests-esm}/unit/Card.test.js (100%) rename tests/{ => tests-esm}/unit/CardGroup.test.js (100%) rename tests/{ => tests-esm}/unit/CardRef.test.js (100%) rename tests/{ => tests-esm}/unit/ChangeList.test.js (100%) rename tests/{ => tests-esm}/unit/Chapter.test.js (100%) rename tests/{ => tests-esm}/unit/Chapters.test.js (100%) rename tests/{ => tests-esm}/unit/Chatbot.test.js (100%) rename tests/{ => tests-esm}/unit/Code.test.js (100%) rename tests/{ => tests-esm}/unit/CodeIO.test.js (100%) rename tests/{ => tests-esm}/unit/ContentsListItem.test.js (100%) rename tests/{ => tests-esm}/unit/DefinitionList.test.js (100%) rename tests/{ => tests-esm}/unit/DeprecatedVersionSelector.test.js (100%) rename tests/{ => tests-esm}/unit/Emphasis.test.js (100%) rename tests/{ => tests-esm}/unit/FeedbackWidget.test.js (100%) rename tests/{ => tests-esm}/unit/Field.test.js (100%) rename tests/{ => tests-esm}/unit/FieldList.test.js (100%) rename tests/{ => tests-esm}/unit/Figure.test.js (100%) rename tests/{ => tests-esm}/unit/Footnote.test.js (100%) rename tests/{ => tests-esm}/unit/FootnoteReference.test.js (100%) rename tests/{ => tests-esm}/unit/GuideNext.test.js (100%) rename tests/{ => tests-esm}/unit/GuidesLandingTree.test.js (100%) rename tests/{ => tests-esm}/unit/GuidesTOCTree.test.js (100%) rename tests/{ => tests-esm}/unit/Head.test.js (100%) rename tests/{ => tests-esm}/unit/Heading.test.js (100%) rename tests/{ => tests-esm}/unit/IA.test.js (100%) rename tests/{ => tests-esm}/unit/InternalPageNav.test.js (100%) rename tests/{ => tests-esm}/unit/Lightbox.test.js (100%) rename tests/{ => tests-esm}/unit/Line.test.js (100%) rename tests/{ => tests-esm}/unit/LineBlock.test.js (100%) rename tests/{ => tests-esm}/unit/Link.test.js (100%) rename tests/{ => tests-esm}/unit/List.test.js (100%) rename tests/{ => tests-esm}/unit/ListTable.test.js (100%) rename tests/{ => tests-esm}/unit/Literal.test.js (100%) rename tests/{ => tests-esm}/unit/LiteralInclude.test.js (100%) rename tests/{ => tests-esm}/unit/Meta.test.js (100%) rename tests/{ => tests-esm}/unit/OpenAPI.test.js (100%) rename tests/{ => tests-esm}/unit/OpenAPIChangelog.test.js (100%) rename tests/{ => tests-esm}/unit/Paragraph.test.js (100%) rename tests/{ => tests-esm}/unit/Presentation.test.js (100%) rename tests/{ => tests-esm}/unit/Procedure.test.js (100%) rename tests/{ => tests-esm}/unit/ProductsList.test.js (100%) rename tests/{ => tests-esm}/unit/QuizWidget.test.js (100%) rename tests/{ => tests-esm}/unit/Reference.test.js (100%) rename tests/{ => tests-esm}/unit/ReleaseSpecification.test.js (100%) rename tests/{ => tests-esm}/unit/Role.test.js (100%) rename tests/{ => tests-esm}/unit/SearchResults.test.js (100%) rename tests/{ => tests-esm}/unit/Section.test.js (100%) rename tests/{ => tests-esm}/unit/Sidenav.test.js (100%) rename tests/{ => tests-esm}/unit/SiteBanner.test.js (100%) rename tests/{ => tests-esm}/unit/Step.test.js (100%) rename tests/{ => tests-esm}/unit/Strong.test.js (100%) rename tests/{ => tests-esm}/unit/Tabs.test.js (100%) rename tests/{ => tests-esm}/unit/Target.test.js (100%) rename tests/{ => tests-esm}/unit/Text.test.js (100%) rename tests/{ => tests-esm}/unit/Time.test.js (100%) rename tests/{ => tests-esm}/unit/Toctree.test.js (100%) rename tests/{ => tests-esm}/unit/VersionDropdown.test.js (100%) rename tests/{ => tests-esm}/unit/VersionModified.test.js (100%) rename tests/{ => tests-esm}/unit/filterHiddenChanges.test.js (100%) rename tests/{ => tests-esm}/unit/utils/assert-trailing-slash.test.js (83%) rename tests/{ => tests-esm}/unit/utils/base-url.test.js (98%) rename tests/{ => tests-esm}/unit/utils/generate-path-prefix.test.js (96%) rename tests/{ => tests-esm}/unit/utils/setup/construct-build-filter.test.js (96%) diff --git a/jest.config.js b/jest.config.js index 32dd9dfcc..23b2b3261 100644 --- a/jest.config.js +++ b/jest.config.js @@ -36,5 +36,9 @@ module.exports = { '^.+\\.jsx?$': `/jest-preprocess.js`, }, }, + { + displayName: 'tests-esm', + testMatch: ['/tests/tests-esm/**/*.test.js'], + }, ], }; diff --git a/package.json b/package.json index 5da746b8c..6ea088e4d 100644 --- a/package.json +++ b/package.json @@ -50,7 +50,7 @@ "prettier": "prettier '**/*.{js,jsx,json,md}'", "preversion": "npm run ensure-master && npm run format && npm run lint && npm run test", "serve": "gatsby serve --prefix-paths", - "test": "jest", + "test": "jest --ignore-projects tests-esm", "test:unit": "jest unit", "version": "auto-changelog -p --template keepachangelog && git add CHANGELOG.md" }, diff --git a/tests/context/toc-context.test.js b/tests/tests-esm/context/toc-context.test.js similarity index 100% rename from tests/context/toc-context.test.js rename to tests/tests-esm/context/toc-context.test.js diff --git a/tests/context/version-context.test.js b/tests/tests-esm/context/version-context.test.js similarity index 100% rename from tests/context/version-context.test.js rename to tests/tests-esm/context/version-context.test.js diff --git a/tests/unit/Admonition.test.js b/tests/tests-esm/unit/Admonition.test.js similarity index 100% rename from tests/unit/Admonition.test.js rename to tests/tests-esm/unit/Admonition.test.js diff --git a/tests/unit/Banner.test.js b/tests/tests-esm/unit/Banner.test.js similarity index 100% rename from tests/unit/Banner.test.js rename to tests/tests-esm/unit/Banner.test.js diff --git a/tests/unit/BlockQuote.test.js b/tests/tests-esm/unit/BlockQuote.test.js similarity index 100% rename from tests/unit/BlockQuote.test.js rename to tests/tests-esm/unit/BlockQuote.test.js diff --git a/tests/unit/BreadcrumbContainer.test.js b/tests/tests-esm/unit/BreadcrumbContainer.test.js similarity index 100% rename from tests/unit/BreadcrumbContainer.test.js rename to tests/tests-esm/unit/BreadcrumbContainer.test.js diff --git a/tests/unit/Breadcrumbs.test.js b/tests/tests-esm/unit/Breadcrumbs.test.js similarity index 100% rename from tests/unit/Breadcrumbs.test.js rename to tests/tests-esm/unit/Breadcrumbs.test.js diff --git a/tests/unit/Button.test.js b/tests/tests-esm/unit/Button.test.js similarity index 100% rename from tests/unit/Button.test.js rename to tests/tests-esm/unit/Button.test.js diff --git a/tests/unit/CTABanner.test.js b/tests/tests-esm/unit/CTABanner.test.js similarity index 100% rename from tests/unit/CTABanner.test.js rename to tests/tests-esm/unit/CTABanner.test.js diff --git a/tests/unit/Card.test.js b/tests/tests-esm/unit/Card.test.js similarity index 100% rename from tests/unit/Card.test.js rename to tests/tests-esm/unit/Card.test.js diff --git a/tests/unit/CardGroup.test.js b/tests/tests-esm/unit/CardGroup.test.js similarity index 100% rename from tests/unit/CardGroup.test.js rename to tests/tests-esm/unit/CardGroup.test.js diff --git a/tests/unit/CardRef.test.js b/tests/tests-esm/unit/CardRef.test.js similarity index 100% rename from tests/unit/CardRef.test.js rename to tests/tests-esm/unit/CardRef.test.js diff --git a/tests/unit/ChangeList.test.js b/tests/tests-esm/unit/ChangeList.test.js similarity index 100% rename from tests/unit/ChangeList.test.js rename to tests/tests-esm/unit/ChangeList.test.js diff --git a/tests/unit/Chapter.test.js b/tests/tests-esm/unit/Chapter.test.js similarity index 100% rename from tests/unit/Chapter.test.js rename to tests/tests-esm/unit/Chapter.test.js diff --git a/tests/unit/Chapters.test.js b/tests/tests-esm/unit/Chapters.test.js similarity index 100% rename from tests/unit/Chapters.test.js rename to tests/tests-esm/unit/Chapters.test.js diff --git a/tests/unit/Chatbot.test.js b/tests/tests-esm/unit/Chatbot.test.js similarity index 100% rename from tests/unit/Chatbot.test.js rename to tests/tests-esm/unit/Chatbot.test.js diff --git a/tests/unit/Code.test.js b/tests/tests-esm/unit/Code.test.js similarity index 100% rename from tests/unit/Code.test.js rename to tests/tests-esm/unit/Code.test.js diff --git a/tests/unit/CodeIO.test.js b/tests/tests-esm/unit/CodeIO.test.js similarity index 100% rename from tests/unit/CodeIO.test.js rename to tests/tests-esm/unit/CodeIO.test.js diff --git a/tests/unit/ContentsListItem.test.js b/tests/tests-esm/unit/ContentsListItem.test.js similarity index 100% rename from tests/unit/ContentsListItem.test.js rename to tests/tests-esm/unit/ContentsListItem.test.js diff --git a/tests/unit/DefinitionList.test.js b/tests/tests-esm/unit/DefinitionList.test.js similarity index 100% rename from tests/unit/DefinitionList.test.js rename to tests/tests-esm/unit/DefinitionList.test.js diff --git a/tests/unit/DeprecatedVersionSelector.test.js b/tests/tests-esm/unit/DeprecatedVersionSelector.test.js similarity index 100% rename from tests/unit/DeprecatedVersionSelector.test.js rename to tests/tests-esm/unit/DeprecatedVersionSelector.test.js diff --git a/tests/unit/Emphasis.test.js b/tests/tests-esm/unit/Emphasis.test.js similarity index 100% rename from tests/unit/Emphasis.test.js rename to tests/tests-esm/unit/Emphasis.test.js diff --git a/tests/unit/FeedbackWidget.test.js b/tests/tests-esm/unit/FeedbackWidget.test.js similarity index 100% rename from tests/unit/FeedbackWidget.test.js rename to tests/tests-esm/unit/FeedbackWidget.test.js diff --git a/tests/unit/Field.test.js b/tests/tests-esm/unit/Field.test.js similarity index 100% rename from tests/unit/Field.test.js rename to tests/tests-esm/unit/Field.test.js diff --git a/tests/unit/FieldList.test.js b/tests/tests-esm/unit/FieldList.test.js similarity index 100% rename from tests/unit/FieldList.test.js rename to tests/tests-esm/unit/FieldList.test.js diff --git a/tests/unit/Figure.test.js b/tests/tests-esm/unit/Figure.test.js similarity index 100% rename from tests/unit/Figure.test.js rename to tests/tests-esm/unit/Figure.test.js diff --git a/tests/unit/Footnote.test.js b/tests/tests-esm/unit/Footnote.test.js similarity index 100% rename from tests/unit/Footnote.test.js rename to tests/tests-esm/unit/Footnote.test.js diff --git a/tests/unit/FootnoteReference.test.js b/tests/tests-esm/unit/FootnoteReference.test.js similarity index 100% rename from tests/unit/FootnoteReference.test.js rename to tests/tests-esm/unit/FootnoteReference.test.js diff --git a/tests/unit/GuideNext.test.js b/tests/tests-esm/unit/GuideNext.test.js similarity index 100% rename from tests/unit/GuideNext.test.js rename to tests/tests-esm/unit/GuideNext.test.js diff --git a/tests/unit/GuidesLandingTree.test.js b/tests/tests-esm/unit/GuidesLandingTree.test.js similarity index 100% rename from tests/unit/GuidesLandingTree.test.js rename to tests/tests-esm/unit/GuidesLandingTree.test.js diff --git a/tests/unit/GuidesTOCTree.test.js b/tests/tests-esm/unit/GuidesTOCTree.test.js similarity index 100% rename from tests/unit/GuidesTOCTree.test.js rename to tests/tests-esm/unit/GuidesTOCTree.test.js diff --git a/tests/unit/Head.test.js b/tests/tests-esm/unit/Head.test.js similarity index 100% rename from tests/unit/Head.test.js rename to tests/tests-esm/unit/Head.test.js diff --git a/tests/unit/Heading.test.js b/tests/tests-esm/unit/Heading.test.js similarity index 100% rename from tests/unit/Heading.test.js rename to tests/tests-esm/unit/Heading.test.js diff --git a/tests/unit/IA.test.js b/tests/tests-esm/unit/IA.test.js similarity index 100% rename from tests/unit/IA.test.js rename to tests/tests-esm/unit/IA.test.js diff --git a/tests/unit/InternalPageNav.test.js b/tests/tests-esm/unit/InternalPageNav.test.js similarity index 100% rename from tests/unit/InternalPageNav.test.js rename to tests/tests-esm/unit/InternalPageNav.test.js diff --git a/tests/unit/Lightbox.test.js b/tests/tests-esm/unit/Lightbox.test.js similarity index 100% rename from tests/unit/Lightbox.test.js rename to tests/tests-esm/unit/Lightbox.test.js diff --git a/tests/unit/Line.test.js b/tests/tests-esm/unit/Line.test.js similarity index 100% rename from tests/unit/Line.test.js rename to tests/tests-esm/unit/Line.test.js diff --git a/tests/unit/LineBlock.test.js b/tests/tests-esm/unit/LineBlock.test.js similarity index 100% rename from tests/unit/LineBlock.test.js rename to tests/tests-esm/unit/LineBlock.test.js diff --git a/tests/unit/Link.test.js b/tests/tests-esm/unit/Link.test.js similarity index 100% rename from tests/unit/Link.test.js rename to tests/tests-esm/unit/Link.test.js diff --git a/tests/unit/List.test.js b/tests/tests-esm/unit/List.test.js similarity index 100% rename from tests/unit/List.test.js rename to tests/tests-esm/unit/List.test.js diff --git a/tests/unit/ListTable.test.js b/tests/tests-esm/unit/ListTable.test.js similarity index 100% rename from tests/unit/ListTable.test.js rename to tests/tests-esm/unit/ListTable.test.js diff --git a/tests/unit/Literal.test.js b/tests/tests-esm/unit/Literal.test.js similarity index 100% rename from tests/unit/Literal.test.js rename to tests/tests-esm/unit/Literal.test.js diff --git a/tests/unit/LiteralInclude.test.js b/tests/tests-esm/unit/LiteralInclude.test.js similarity index 100% rename from tests/unit/LiteralInclude.test.js rename to tests/tests-esm/unit/LiteralInclude.test.js diff --git a/tests/unit/Meta.test.js b/tests/tests-esm/unit/Meta.test.js similarity index 100% rename from tests/unit/Meta.test.js rename to tests/tests-esm/unit/Meta.test.js diff --git a/tests/unit/OpenAPI.test.js b/tests/tests-esm/unit/OpenAPI.test.js similarity index 100% rename from tests/unit/OpenAPI.test.js rename to tests/tests-esm/unit/OpenAPI.test.js diff --git a/tests/unit/OpenAPIChangelog.test.js b/tests/tests-esm/unit/OpenAPIChangelog.test.js similarity index 100% rename from tests/unit/OpenAPIChangelog.test.js rename to tests/tests-esm/unit/OpenAPIChangelog.test.js diff --git a/tests/unit/Paragraph.test.js b/tests/tests-esm/unit/Paragraph.test.js similarity index 100% rename from tests/unit/Paragraph.test.js rename to tests/tests-esm/unit/Paragraph.test.js diff --git a/tests/unit/Presentation.test.js b/tests/tests-esm/unit/Presentation.test.js similarity index 100% rename from tests/unit/Presentation.test.js rename to tests/tests-esm/unit/Presentation.test.js diff --git a/tests/unit/Procedure.test.js b/tests/tests-esm/unit/Procedure.test.js similarity index 100% rename from tests/unit/Procedure.test.js rename to tests/tests-esm/unit/Procedure.test.js diff --git a/tests/unit/ProductsList.test.js b/tests/tests-esm/unit/ProductsList.test.js similarity index 100% rename from tests/unit/ProductsList.test.js rename to tests/tests-esm/unit/ProductsList.test.js diff --git a/tests/unit/QuizWidget.test.js b/tests/tests-esm/unit/QuizWidget.test.js similarity index 100% rename from tests/unit/QuizWidget.test.js rename to tests/tests-esm/unit/QuizWidget.test.js diff --git a/tests/unit/Reference.test.js b/tests/tests-esm/unit/Reference.test.js similarity index 100% rename from tests/unit/Reference.test.js rename to tests/tests-esm/unit/Reference.test.js diff --git a/tests/unit/ReleaseSpecification.test.js b/tests/tests-esm/unit/ReleaseSpecification.test.js similarity index 100% rename from tests/unit/ReleaseSpecification.test.js rename to tests/tests-esm/unit/ReleaseSpecification.test.js diff --git a/tests/unit/Role.test.js b/tests/tests-esm/unit/Role.test.js similarity index 100% rename from tests/unit/Role.test.js rename to tests/tests-esm/unit/Role.test.js diff --git a/tests/unit/SearchResults.test.js b/tests/tests-esm/unit/SearchResults.test.js similarity index 100% rename from tests/unit/SearchResults.test.js rename to tests/tests-esm/unit/SearchResults.test.js diff --git a/tests/unit/Section.test.js b/tests/tests-esm/unit/Section.test.js similarity index 100% rename from tests/unit/Section.test.js rename to tests/tests-esm/unit/Section.test.js diff --git a/tests/unit/Sidenav.test.js b/tests/tests-esm/unit/Sidenav.test.js similarity index 100% rename from tests/unit/Sidenav.test.js rename to tests/tests-esm/unit/Sidenav.test.js diff --git a/tests/unit/SiteBanner.test.js b/tests/tests-esm/unit/SiteBanner.test.js similarity index 100% rename from tests/unit/SiteBanner.test.js rename to tests/tests-esm/unit/SiteBanner.test.js diff --git a/tests/unit/Step.test.js b/tests/tests-esm/unit/Step.test.js similarity index 100% rename from tests/unit/Step.test.js rename to tests/tests-esm/unit/Step.test.js diff --git a/tests/unit/Strong.test.js b/tests/tests-esm/unit/Strong.test.js similarity index 100% rename from tests/unit/Strong.test.js rename to tests/tests-esm/unit/Strong.test.js diff --git a/tests/unit/Tabs.test.js b/tests/tests-esm/unit/Tabs.test.js similarity index 100% rename from tests/unit/Tabs.test.js rename to tests/tests-esm/unit/Tabs.test.js diff --git a/tests/unit/Target.test.js b/tests/tests-esm/unit/Target.test.js similarity index 100% rename from tests/unit/Target.test.js rename to tests/tests-esm/unit/Target.test.js diff --git a/tests/unit/Text.test.js b/tests/tests-esm/unit/Text.test.js similarity index 100% rename from tests/unit/Text.test.js rename to tests/tests-esm/unit/Text.test.js diff --git a/tests/unit/Time.test.js b/tests/tests-esm/unit/Time.test.js similarity index 100% rename from tests/unit/Time.test.js rename to tests/tests-esm/unit/Time.test.js diff --git a/tests/unit/Toctree.test.js b/tests/tests-esm/unit/Toctree.test.js similarity index 100% rename from tests/unit/Toctree.test.js rename to tests/tests-esm/unit/Toctree.test.js diff --git a/tests/unit/VersionDropdown.test.js b/tests/tests-esm/unit/VersionDropdown.test.js similarity index 100% rename from tests/unit/VersionDropdown.test.js rename to tests/tests-esm/unit/VersionDropdown.test.js diff --git a/tests/unit/VersionModified.test.js b/tests/tests-esm/unit/VersionModified.test.js similarity index 100% rename from tests/unit/VersionModified.test.js rename to tests/tests-esm/unit/VersionModified.test.js diff --git a/tests/unit/filterHiddenChanges.test.js b/tests/tests-esm/unit/filterHiddenChanges.test.js similarity index 100% rename from tests/unit/filterHiddenChanges.test.js rename to tests/tests-esm/unit/filterHiddenChanges.test.js diff --git a/tests/unit/utils/assert-trailing-slash.test.js b/tests/tests-esm/unit/utils/assert-trailing-slash.test.js similarity index 83% rename from tests/unit/utils/assert-trailing-slash.test.js rename to tests/tests-esm/unit/utils/assert-trailing-slash.test.js index f17ffb354..fcce8cf7b 100644 --- a/tests/unit/utils/assert-trailing-slash.test.js +++ b/tests/tests-esm/unit/utils/assert-trailing-slash.test.js @@ -1,4 +1,4 @@ -import { assertTrailingSlash } from '../../../src/utils/assert-trailing-slash'; +import { assertTrailingSlash } from '../../../../src/utils/assert-trailing-slash.mjs'; it('should add trailing slashes to links if they are missing', () => { const linkWithoutSlash = 'foo.bar'; diff --git a/tests/unit/utils/base-url.test.js b/tests/tests-esm/unit/utils/base-url.test.js similarity index 98% rename from tests/unit/utils/base-url.test.js rename to tests/tests-esm/unit/utils/base-url.test.js index 303898d48..2324e417c 100644 --- a/tests/unit/utils/base-url.test.js +++ b/tests/tests-esm/unit/utils/base-url.test.js @@ -1,4 +1,4 @@ -import { baseUrl } from '../../../src/utils/base-url'; +import { baseUrl } from '../../../../src/utils/base-url.mjs'; describe('baseUrl', () => { it('by default returns the DOTCOM_BASE_URL with protocols and prefix, with a trailing slash', () => { diff --git a/tests/unit/utils/generate-path-prefix.test.js b/tests/tests-esm/unit/utils/generate-path-prefix.test.js similarity index 96% rename from tests/unit/utils/generate-path-prefix.test.js rename to tests/tests-esm/unit/utils/generate-path-prefix.test.js index b686d0422..1ae544d42 100644 --- a/tests/unit/utils/generate-path-prefix.test.js +++ b/tests/tests-esm/unit/utils/generate-path-prefix.test.js @@ -1,4 +1,4 @@ -import { generatePathPrefix } from '../../../src/utils/generate-path-prefix'; +import { generatePathPrefix } from '../../../../src/utils/generate-path-prefix.mjs'; describe('path prefix testing', () => { const commitHash = 'COMMIT_HASH'; diff --git a/tests/unit/utils/setup/construct-build-filter.test.js b/tests/tests-esm/unit/utils/setup/construct-build-filter.test.js similarity index 96% rename from tests/unit/utils/setup/construct-build-filter.test.js rename to tests/tests-esm/unit/utils/setup/construct-build-filter.test.js index 3bdce35cf..374426177 100644 --- a/tests/unit/utils/setup/construct-build-filter.test.js +++ b/tests/tests-esm/unit/utils/setup/construct-build-filter.test.js @@ -1,4 +1,4 @@ -import { constructBuildFilter } from '../../../../src/utils/setup/construct-build-filter'; +import { constructBuildFilter } from '../../../../../src/utils/setup/construct-build-filter.mjs'; // Mock page documents found in snooty_.documents const mockPageDocs = [ From 525fddaa3fea0d196b493e856b03107156cbe12e Mon Sep 17 00:00:00 2001 From: Maya Raman Date: Fri, 8 Dec 2023 15:31:46 -0500 Subject: [PATCH 09/13] import statements --- tests/tests-esm/context/toc-context.test.js | 10 +++++----- tests/tests-esm/context/version-context.test.js | 8 ++++---- tests/tests-esm/unit/Admonition.test.js | 4 ++-- tests/tests-esm/unit/Banner.test.js | 4 ++-- tests/tests-esm/unit/BlockQuote.test.js | 6 +++--- tests/tests-esm/unit/BreadcrumbContainer.test.js | 6 +++--- tests/tests-esm/unit/Breadcrumbs.test.js | 6 +++--- tests/tests-esm/unit/Button.test.js | 8 ++++---- tests/tests-esm/unit/CTABanner.test.js | 6 +++--- tests/tests-esm/unit/Card.test.js | 8 ++++---- tests/tests-esm/unit/CardGroup.test.js | 8 ++++---- tests/tests-esm/unit/CardRef.test.js | 8 ++++---- tests/tests-esm/unit/ChangeList.test.js | 6 +++--- tests/tests-esm/unit/Chapter.test.js | 6 +++--- tests/tests-esm/unit/Chapters.test.js | 16 ++++++++-------- tests/tests-esm/unit/Chatbot.test.js | 2 +- tests/tests-esm/unit/Code.test.js | 10 +++++----- tests/tests-esm/unit/CodeIO.test.js | 4 ++-- tests/tests-esm/unit/ContentsListItem.test.js | 4 ++-- tests/tests-esm/unit/DefinitionList.test.js | 4 ++-- .../unit/DeprecatedVersionSelector.test.js | 4 ++-- tests/tests-esm/unit/Emphasis.test.js | 4 ++-- tests/tests-esm/unit/FeedbackWidget.test.js | 14 +++++++------- tests/tests-esm/unit/Field.test.js | 4 ++-- tests/tests-esm/unit/FieldList.test.js | 6 +++--- tests/tests-esm/unit/Figure.test.js | 8 ++++---- tests/tests-esm/unit/Footnote.test.js | 6 +++--- tests/tests-esm/unit/FootnoteReference.test.js | 4 ++-- tests/tests-esm/unit/GuideNext.test.js | 10 +++++----- tests/tests-esm/unit/GuidesLandingTree.test.js | 6 +++--- tests/tests-esm/unit/GuidesTOCTree.test.js | 8 ++++---- tests/tests-esm/unit/Head.test.js | 16 ++++++++-------- tests/tests-esm/unit/Heading.test.js | 4 ++-- tests/tests-esm/unit/IA.test.js | 8 ++++---- tests/tests-esm/unit/InternalPageNav.test.js | 6 +++--- tests/tests-esm/unit/Lightbox.test.js | 4 ++-- tests/tests-esm/unit/Line.test.js | 6 +++--- tests/tests-esm/unit/LineBlock.test.js | 4 ++-- tests/tests-esm/unit/Link.test.js | 4 ++-- tests/tests-esm/unit/List.test.js | 4 ++-- tests/tests-esm/unit/ListTable.test.js | 6 +++--- tests/tests-esm/unit/Literal.test.js | 4 ++-- tests/tests-esm/unit/LiteralInclude.test.js | 4 ++-- tests/tests-esm/unit/Meta.test.js | 6 +++--- tests/tests-esm/unit/OpenAPI.test.js | 2 +- tests/tests-esm/unit/OpenAPIChangelog.test.js | 6 +++--- tests/tests-esm/unit/Paragraph.test.js | 8 ++++---- tests/tests-esm/unit/Presentation.test.js | 8 ++++---- tests/tests-esm/unit/Procedure.test.js | 6 +++--- tests/tests-esm/unit/ProductsList.test.js | 6 +++--- tests/tests-esm/unit/QuizWidget.test.js | 4 ++-- tests/tests-esm/unit/Reference.test.js | 6 +++--- .../tests-esm/unit/ReleaseSpecification.test.js | 4 ++-- tests/tests-esm/unit/Role.test.js | 12 ++++++------ tests/tests-esm/unit/SearchResults.test.js | 16 ++++++++-------- tests/tests-esm/unit/Section.test.js | 4 ++-- tests/tests-esm/unit/Sidenav.test.js | 8 ++++---- tests/tests-esm/unit/SiteBanner.test.js | 8 ++++---- tests/tests-esm/unit/Step.test.js | 6 +++--- tests/tests-esm/unit/Strong.test.js | 4 ++-- tests/tests-esm/unit/Tabs.test.js | 14 +++++++------- tests/tests-esm/unit/Target.test.js | 6 +++--- tests/tests-esm/unit/Text.test.js | 4 ++-- tests/tests-esm/unit/Time.test.js | 4 ++-- tests/tests-esm/unit/Toctree.test.js | 8 ++++---- tests/tests-esm/unit/VersionDropdown.test.js | 12 ++++++------ tests/tests-esm/unit/VersionModified.test.js | 4 ++-- tests/tests-esm/unit/filterHiddenChanges.test.js | 10 +++++----- 68 files changed, 227 insertions(+), 227 deletions(-) diff --git a/tests/tests-esm/context/toc-context.test.js b/tests/tests-esm/context/toc-context.test.js index c020bf7ac..a26cf426e 100644 --- a/tests/tests-esm/context/toc-context.test.js +++ b/tests/tests-esm/context/toc-context.test.js @@ -1,12 +1,12 @@ import React, { useContext } from 'react'; import { act } from 'react-dom/test-utils'; import { render } from '@testing-library/react'; -import * as realm from '../../src/utils/realm'; -import * as siteMetadata from '../../src/hooks/use-site-metadata'; -import * as snootyMetadata from '../../src/utils/use-snooty-metadata'; -import { VersionContext } from '../../src/context/version-context'; +import * as realm from '../../../src/utils/realm'; +import * as siteMetadata from '../../../src/hooks/use-site-metadata'; +import * as snootyMetadata from '../../../src/utils/use-snooty-metadata'; +import { VersionContext } from '../../../src/context/version-context'; -import { TocContext, TocContextProvider } from '../../src/context/toc-context'; +import { TocContext, TocContextProvider } from '../../../src/context/toc-context'; // <------------------ START test data mocks ------------------> const siteMetadataMock = jest.spyOn(siteMetadata, 'useSiteMetadata'); diff --git a/tests/tests-esm/context/version-context.test.js b/tests/tests-esm/context/version-context.test.js index f1796f009..807a50855 100644 --- a/tests/tests-esm/context/version-context.test.js +++ b/tests/tests-esm/context/version-context.test.js @@ -3,10 +3,10 @@ import * as Gatsby from 'gatsby'; import { render } from '@testing-library/react'; import userEvent from '@testing-library/user-event'; import { act } from 'react-dom/test-utils'; -import { VersionContextProvider, VersionContext, STORAGE_KEY } from '../../src/context/version-context'; -import * as browserStorage from '../../src/utils/browser-storage'; -import * as realm from '../../src/utils/realm'; -import * as snootyMetadata from '../../src/utils/use-snooty-metadata'; +import { VersionContextProvider, VersionContext, STORAGE_KEY } from '../../../src/context/version-context'; +import * as browserStorage from '../../../src/utils/browser-storage'; +import * as realm from '../../../src/utils/realm'; +import * as snootyMetadata from '../../../src/utils/use-snooty-metadata'; const snootyMetadataMock = jest.spyOn(snootyMetadata, 'default'); const useStaticQuery = jest.spyOn(Gatsby, 'useStaticQuery'); diff --git a/tests/tests-esm/unit/Admonition.test.js b/tests/tests-esm/unit/Admonition.test.js index 365ad83b4..31a3b410c 100644 --- a/tests/tests-esm/unit/Admonition.test.js +++ b/tests/tests-esm/unit/Admonition.test.js @@ -1,9 +1,9 @@ import React from 'react'; import { render } from '@testing-library/react'; -import Admonition from '../../src/components/Admonition'; +import Admonition from '../../../src/components/Admonition.js'; // data for this component -import mockData from './data/Admonition.test.json'; +import mockData from '../../unit/data/Admonition.test.json'; it('admonitions render correctly', () => { const tree = render(); diff --git a/tests/tests-esm/unit/Banner.test.js b/tests/tests-esm/unit/Banner.test.js index d55bf7093..216f6a34b 100644 --- a/tests/tests-esm/unit/Banner.test.js +++ b/tests/tests-esm/unit/Banner.test.js @@ -1,9 +1,9 @@ import React from 'react'; import { render } from '@testing-library/react'; -import Banner from '../../src/components/Banner/Banner'; +import Banner from '../../../src/components/Banner/Banner'; // data for this component -import mockData from './data/Banner.test.json'; +import mockData from '../../unit/data/Banner.test.json'; it('renders a Banner correctly', () => { const wrapper = render(); diff --git a/tests/tests-esm/unit/BlockQuote.test.js b/tests/tests-esm/unit/BlockQuote.test.js index 915a04031..549490f98 100644 --- a/tests/tests-esm/unit/BlockQuote.test.js +++ b/tests/tests-esm/unit/BlockQuote.test.js @@ -1,10 +1,10 @@ import React from 'react'; import { render } from '@testing-library/react'; -import { mockLocation } from '../utils/mock-location'; -import BlockQuote from '../../src/components/BlockQuote'; +import { mockLocation } from '../../utils/mock-location'; +import BlockQuote from '../../../src/components/BlockQuote'; // data for this component -import mockData from './data/BlockQuote.test.json'; +import mockData from '../../unit/data/BlockQuote.test.json'; beforeAll(() => { mockLocation(null, `/`); diff --git a/tests/tests-esm/unit/BreadcrumbContainer.test.js b/tests/tests-esm/unit/BreadcrumbContainer.test.js index b92538de0..bd276c701 100644 --- a/tests/tests-esm/unit/BreadcrumbContainer.test.js +++ b/tests/tests-esm/unit/BreadcrumbContainer.test.js @@ -1,8 +1,8 @@ import React from 'react'; import { render } from '@testing-library/react'; -import { mockLocation } from '../utils/mock-location'; -import BreadcrumbContainer from '../../src/components/Breadcrumbs/BreadcrumbContainer'; -import { NavigationContext } from '../../src/context/navigation-context'; +import { mockLocation } from '../../utils/mock-location'; +import BreadcrumbContainer from '../../../src/components/Breadcrumbs/BreadcrumbContainer'; +import { NavigationContext } from '../../../src/context/navigation-context'; const mountBreadcrumbContainer = (homeCrumb, lastCrumb, parents) => { return render( diff --git a/tests/tests-esm/unit/Breadcrumbs.test.js b/tests/tests-esm/unit/Breadcrumbs.test.js index 5f4030a57..b53b2e3d0 100644 --- a/tests/tests-esm/unit/Breadcrumbs.test.js +++ b/tests/tests-esm/unit/Breadcrumbs.test.js @@ -1,10 +1,10 @@ import React from 'react'; import * as Gatsby from 'gatsby'; import { render } from '@testing-library/react'; -import { mockLocation } from '../utils/mock-location'; -import Breadcrumbs from '../../src/components/Breadcrumbs/index'; +import { mockLocation } from '../../utils/mock-location'; +import Breadcrumbs from '../../../src/components/Breadcrumbs/index'; -import mockData from './data/Breadcrumbs.test.json'; +import mockData from '../../unit/data/Breadcrumbs.test.json'; it('renders correctly with siteTitle', () => { const tree = render(); diff --git a/tests/tests-esm/unit/Button.test.js b/tests/tests-esm/unit/Button.test.js index 5ddf86ed7..e631410b0 100644 --- a/tests/tests-esm/unit/Button.test.js +++ b/tests/tests-esm/unit/Button.test.js @@ -1,11 +1,11 @@ import React from 'react'; import { render } from '@testing-library/react'; -import { mockLocation } from '../utils/mock-location'; -import Button from '../../src/components/Button'; +import { mockLocation } from '../../utils/mock-location'; +import Button from '../../../src/components/Button'; // data for this component -import Link from '../../src/components/Link'; -import mockData from './data/Button.test.json'; +import Link from '../../../src/components/Link'; +import mockData from '../../unit/data/Button.test.json'; jest.mock('../../src/components/Link'); diff --git a/tests/tests-esm/unit/CTABanner.test.js b/tests/tests-esm/unit/CTABanner.test.js index 84e22ed43..a47fd7866 100644 --- a/tests/tests-esm/unit/CTABanner.test.js +++ b/tests/tests-esm/unit/CTABanner.test.js @@ -1,10 +1,10 @@ import React from 'react'; import { render } from '@testing-library/react'; -import { mockLocation } from '../utils/mock-location'; -import CTABanner from '../../src/components/Banner/CTABanner'; +import { mockLocation } from '../../utils/mock-location'; +import CTABanner from '../../../src/components/Banner/CTABanner'; // data for this component -import mockData from './data/CTABanner.test.json'; +import mockData from '../../unit/data/CTABanner.test.json'; beforeAll(() => { mockLocation(null, `/`); diff --git a/tests/tests-esm/unit/Card.test.js b/tests/tests-esm/unit/Card.test.js index 04ac1dcd3..6ef0f52e0 100644 --- a/tests/tests-esm/unit/Card.test.js +++ b/tests/tests-esm/unit/Card.test.js @@ -2,12 +2,12 @@ import React from 'react'; import { render } from '@testing-library/react'; import { ThemeProvider } from '@emotion/react'; import { navigate } from 'gatsby'; -import { mockLocation } from '../utils/mock-location'; -import Card from '../../src/components/Card'; -import { theme } from '../../src/theme/docsTheme'; +import { mockLocation } from '../../utils/mock-location'; +import Card from '../../../src/components/Card'; +import { theme } from '../../../src/theme/docsTheme'; // data for this component -import mockData from './data/Card.test.json'; +import mockData from '../../unit/data/Card.test.json'; it('renders correctly', () => { const tree = render( diff --git a/tests/tests-esm/unit/CardGroup.test.js b/tests/tests-esm/unit/CardGroup.test.js index ba7ae4c29..93bb03592 100644 --- a/tests/tests-esm/unit/CardGroup.test.js +++ b/tests/tests-esm/unit/CardGroup.test.js @@ -1,11 +1,11 @@ import React from 'react'; import { render } from '@testing-library/react'; import { ThemeProvider } from '@emotion/react'; -import { mockLocation } from '../utils/mock-location'; -import CardGroup from '../../src/components/Card/CardGroup'; -import { theme } from '../../src/theme/docsTheme'; +import { mockLocation } from '../../utils/mock-location'; +import CardGroup from '../../../src/components/Card/CardGroup'; +import { theme } from '../../../src/theme/docsTheme'; // data for this component -import mockData from './data/CardGroup.test.json'; +import mockData from '../../unit/data/CardGroup.test.json'; beforeAll(() => { mockLocation(null, `/`); diff --git a/tests/tests-esm/unit/CardRef.test.js b/tests/tests-esm/unit/CardRef.test.js index e0c92c91b..5ae36dff2 100644 --- a/tests/tests-esm/unit/CardRef.test.js +++ b/tests/tests-esm/unit/CardRef.test.js @@ -1,12 +1,12 @@ import React from 'react'; import { render } from '@testing-library/react'; import { ThemeProvider } from '@emotion/react'; -import { mockLocation } from '../utils/mock-location'; -import CardGroup from '../../src/components/Card/CardGroup'; -import { theme } from '../../src/theme/docsTheme'; +import { mockLocation } from '../../utils/mock-location'; +import CardGroup from '../../../src/components/Card/CardGroup'; +import { theme } from '../../../src/theme/docsTheme'; // data for this component -import mockData from './data/CardRef.test.json'; +import mockData from '../../unit/data/CardRef.test.json'; beforeAll(() => { mockLocation(null, `/`); diff --git a/tests/tests-esm/unit/ChangeList.test.js b/tests/tests-esm/unit/ChangeList.test.js index 3b3f90382..af711e4cc 100644 --- a/tests/tests-esm/unit/ChangeList.test.js +++ b/tests/tests-esm/unit/ChangeList.test.js @@ -1,9 +1,9 @@ import React from 'react'; import * as Gatsby from 'gatsby'; import { render } from '@testing-library/react'; -import ChangeList from '../../src/components/OpenAPIChangelog/components/ChangeList'; -import { ALL_VERSIONS, COMPARE_VERSIONS } from '../../src/components/OpenAPIChangelog/utils/constants'; -import { mockChangelog, mockDiff } from './data/OpenAPIChangelog'; +import ChangeList from '../../../src/components/OpenAPIChangelog/components/ChangeList'; +import { ALL_VERSIONS, COMPARE_VERSIONS } from '../../../src/components/OpenAPIChangelog/utils/constants'; +import { mockChangelog, mockDiff } from '../../unit/data/OpenAPIChangelog'; jest.mock('../../src/utils/use-snooty-metadata', () => () => ({ openapi_pages: ['reference/api-resources-spec/v2'], diff --git a/tests/tests-esm/unit/Chapter.test.js b/tests/tests-esm/unit/Chapter.test.js index 5038bf0a4..ea96867de 100644 --- a/tests/tests-esm/unit/Chapter.test.js +++ b/tests/tests-esm/unit/Chapter.test.js @@ -1,8 +1,8 @@ import React from 'react'; import { render } from '@testing-library/react'; -import { mockLocation } from '../utils/mock-location'; -import Chapter from '../../src/components/Chapters/Chapter'; -import mockData from './data/Chapters.test.json'; +import { mockLocation } from '../../utils/mock-location'; +import Chapter from '../../../src/components/Chapters/Chapter'; +import mockData from '../../unit/data/Chapters.test.json'; beforeAll(() => { mockLocation(null, `/`); diff --git a/tests/tests-esm/unit/Chapters.test.js b/tests/tests-esm/unit/Chapters.test.js index 410a2f299..ec87aa0a6 100644 --- a/tests/tests-esm/unit/Chapters.test.js +++ b/tests/tests-esm/unit/Chapters.test.js @@ -2,14 +2,14 @@ import React from 'react'; import { ThemeProvider } from '@emotion/react'; import { render } from '@testing-library/react'; import userEvent from '@testing-library/user-event'; -import { mockLocation } from '../utils/mock-location'; -import Chapters from '../../src/components/Chapters'; -import { tick } from '../utils'; -import { SidenavContext } from '../../src/components/Sidenav'; -import { theme } from '../../src/theme/docsTheme'; -import * as useActiveHeading from '../../src/hooks/useActiveHeading'; -import { getPlaintext } from '../../src/utils/get-plaintext'; -import mockData from './data/Chapters.test.json'; +import { mockLocation } from '../../utils/mock-location'; +import Chapters from '../../../src/components/Chapters'; +import { tick } from '../../utils'; +import { SidenavContext } from '../../../src/components/Sidenav'; +import { theme } from '../../../src/theme/docsTheme'; +import * as useActiveHeading from '../../../src/hooks/useActiveHeading'; +import { getPlaintext } from '../../../src/utils/get-plaintext.mjs'; +import mockData from '../../unit/data/Chapters.test.json'; const mountChapters = () => { const { nodeData, metadata } = mockData; diff --git a/tests/tests-esm/unit/Chatbot.test.js b/tests/tests-esm/unit/Chatbot.test.js index 708a7e601..2f174ae22 100644 --- a/tests/tests-esm/unit/Chatbot.test.js +++ b/tests/tests-esm/unit/Chatbot.test.js @@ -1,6 +1,6 @@ import React from 'react'; import { render, waitFor } from '@testing-library/react'; -import ComponentFactory from '../../src/components/ComponentFactory'; +import ComponentFactory from '../../../src/components/ComponentFactory'; jest.mock('../../src/hooks/use-site-metadata', () => ({ useSiteMetadata: () => ({ reposDatabase: 'pool_test' }), diff --git a/tests/tests-esm/unit/Code.test.js b/tests/tests-esm/unit/Code.test.js index 6046a700b..dddce9687 100644 --- a/tests/tests-esm/unit/Code.test.js +++ b/tests/tests-esm/unit/Code.test.js @@ -1,12 +1,12 @@ import React from 'react'; import { render } from '@testing-library/react'; -import Code from '../../src/components/Code/Code'; -import { CodeProvider } from '../../src/components/Code/code-context'; -import { TabProvider } from '../../src/components/Tabs/tab-context'; -import * as browserStorage from '../../src/utils/browser-storage'; +import Code from '../../../src/components/Code/Code'; +import { CodeProvider } from '../../../src/components/Code/code-context'; +import { TabProvider } from '../../../src/components/Tabs/tab-context'; +import * as browserStorage from '../../../src/utils/browser-storage'; // data for this component -import mockData from './data/Code.test.json'; +import mockData from '../../unit/data/Code.test.json'; const mockSelectors = { drivers: { diff --git a/tests/tests-esm/unit/CodeIO.test.js b/tests/tests-esm/unit/CodeIO.test.js index 4debb6a3b..76e08c289 100644 --- a/tests/tests-esm/unit/CodeIO.test.js +++ b/tests/tests-esm/unit/CodeIO.test.js @@ -1,10 +1,10 @@ import React from 'react'; import { render } from '@testing-library/react'; import userEvent from '@testing-library/user-event'; -import CodeIO from '../../src/components/Code/CodeIO'; +import CodeIO from '../../../src/components/Code/CodeIO'; // data for this component -import mockData from './data/CodeIO.test.json'; +import mockData from '../../unit/data/CodeIO.test.json'; describe('CodeIO', () => { it('renders correctly', () => { diff --git a/tests/tests-esm/unit/ContentsListItem.test.js b/tests/tests-esm/unit/ContentsListItem.test.js index e5cdfdc5a..846242eb1 100644 --- a/tests/tests-esm/unit/ContentsListItem.test.js +++ b/tests/tests-esm/unit/ContentsListItem.test.js @@ -1,7 +1,7 @@ import React from 'react'; import { render } from '@testing-library/react'; -import { mockLocation } from '../utils/mock-location'; -import ContentsListItem from '../../src/components/Contents/ContentsListItem'; +import { mockLocation } from '../../utils/mock-location'; +import ContentsListItem from '../../../src/components/Contents/ContentsListItem'; beforeAll(() => { mockLocation(null, `/`); diff --git a/tests/tests-esm/unit/DefinitionList.test.js b/tests/tests-esm/unit/DefinitionList.test.js index b4f053a52..1f2d5ea74 100644 --- a/tests/tests-esm/unit/DefinitionList.test.js +++ b/tests/tests-esm/unit/DefinitionList.test.js @@ -1,7 +1,7 @@ import React from 'react'; import { render } from '@testing-library/react'; -import DefinitionList from '../../src/components/DefinitionList'; -import mockData from './data/DefinitionList.test.json'; +import DefinitionList from '../../../src/components/DefinitionList'; +import mockData from '../../unit/data/DefinitionList.test.json'; it('DefinitionList renders correctly', () => { const tree = render(); diff --git a/tests/tests-esm/unit/DeprecatedVersionSelector.test.js b/tests/tests-esm/unit/DeprecatedVersionSelector.test.js index 04d9ca5fb..4a42560a9 100644 --- a/tests/tests-esm/unit/DeprecatedVersionSelector.test.js +++ b/tests/tests-esm/unit/DeprecatedVersionSelector.test.js @@ -1,8 +1,8 @@ import React from 'react'; import { render, waitFor } from '@testing-library/react'; import userEvent from '@testing-library/user-event'; -import DeprecatedVersionSelector from '../../src/components/DeprecatedVersionSelector'; -import * as realm from '../../src/utils/realm'; +import DeprecatedVersionSelector from '../../../src/components/DeprecatedVersionSelector'; +import * as realm from '../../../src/utils/realm'; const deprecatedVersions = { docs: ['v2.2', 'v2.4', 'v2.6', 'v3.0', 'v3.2', 'v3.4'], diff --git a/tests/tests-esm/unit/Emphasis.test.js b/tests/tests-esm/unit/Emphasis.test.js index a5c3b31c8..9dcba3a51 100644 --- a/tests/tests-esm/unit/Emphasis.test.js +++ b/tests/tests-esm/unit/Emphasis.test.js @@ -1,9 +1,9 @@ import React from 'react'; import { render } from '@testing-library/react'; -import Emphasis from '../../src/components/Emphasis'; +import Emphasis from '../../../src/components/Emphasis'; // data for this component -import mockData from './data/Emphasis.test.json'; +import mockData from '../../unit/data/Emphasis.test.json'; it('renders correctly', () => { const tree = render(); diff --git a/tests/tests-esm/unit/FeedbackWidget.test.js b/tests/tests-esm/unit/FeedbackWidget.test.js index 8e6a06ec2..a293d1e7e 100644 --- a/tests/tests-esm/unit/FeedbackWidget.test.js +++ b/tests/tests-esm/unit/FeedbackWidget.test.js @@ -7,22 +7,22 @@ import { FeedbackForm, FeedbackTab, FeedbackFooter, -} from '../../src/components/Widgets/FeedbackWidget'; +} from '../../../src/components/Widgets/FeedbackWidget'; -import { tick, mockMutationObserver, mockSegmentAnalytics, setDesktop, setMobile, setTablet } from '../utils'; +import { tick, mockMutationObserver, mockSegmentAnalytics, setDesktop, setMobile, setTablet } from '../../utils'; import { stitchFunctionMocks, mockStitchFunctions, clearMockStitchFunctions, -} from '../utils/feedbackWidgetStitchFunctions'; -import Heading from '../../src/components/Heading'; -import { theme } from '../../src/theme/docsTheme'; +} from '../../utils/feedbackWidgetStitchFunctions'; +import Heading from '../../../src/components/Heading'; +import { theme } from '../../../src/theme/docsTheme'; import { screenshotFunctionMocks, mockScreenshotFunctions, clearMockScreenshotFunctions, -} from '../utils/data/feedbackWidgetScreenshotFunctions'; -import headingData from './data/Heading.test.json'; +} from '../../utils/data/feedbackWidgetScreenshotFunctions'; +import headingData from '../../unit/data/Heading.test.json'; async function mountFormWithFeedbackState(feedbackState = {}, options = {}) { const { view, isSupportRequest, hideHeader, screenshotTaken, ...feedback } = feedbackState; diff --git a/tests/tests-esm/unit/Field.test.js b/tests/tests-esm/unit/Field.test.js index 3e223ae60..d484e8036 100644 --- a/tests/tests-esm/unit/Field.test.js +++ b/tests/tests-esm/unit/Field.test.js @@ -1,9 +1,9 @@ import React from 'react'; import { render } from '@testing-library/react'; -import Field from '../../src/components/FieldList/Field'; +import Field from '../../../src/components/FieldList/Field'; // data for this component -import mockData from './data/FieldList.test.json'; +import mockData from '../../unit/data/FieldList.test.json'; it('renders correctly', () => { const tree = render(); diff --git a/tests/tests-esm/unit/FieldList.test.js b/tests/tests-esm/unit/FieldList.test.js index 26d3eb142..9f9d9cc97 100644 --- a/tests/tests-esm/unit/FieldList.test.js +++ b/tests/tests-esm/unit/FieldList.test.js @@ -1,10 +1,10 @@ import React from 'react'; import { render } from '@testing-library/react'; import { ThemeProvider } from '@emotion/react'; -import FieldList from '../../src/components/FieldList'; -import { theme } from '../../src/theme/docsTheme'; +import FieldList from '../../../src/components/FieldList'; +import { theme } from '../../../src/theme/docsTheme'; // data for this component -import mockData from './data/FieldList.test.json'; +import mockData from '../../unit/data/FieldList.test.json'; it('renders correctly', () => { const tree = render( diff --git a/tests/tests-esm/unit/Figure.test.js b/tests/tests-esm/unit/Figure.test.js index f776eb1db..0adae4081 100644 --- a/tests/tests-esm/unit/Figure.test.js +++ b/tests/tests-esm/unit/Figure.test.js @@ -1,11 +1,11 @@ import React from 'react'; import { render } from '@testing-library/react'; -import Figure from '../../src/components/Figure'; +import Figure from '../../../src/components/Figure'; // data for this component -import mockData from './data/Figure.test.json'; -import borderData from './data/FigureBorder.test.json'; -import lightboxData from './data/FigureLightbox.test.json'; +import mockData from '../../unit/data/Figure.test.json'; +import borderData from '../../unit/data/FigureBorder.test.json'; +import lightboxData from '../../unit/data/FigureLightbox.test.json'; it('renders correctly', () => { const tree = render(
); diff --git a/tests/tests-esm/unit/Footnote.test.js b/tests/tests-esm/unit/Footnote.test.js index 3347fe76f..71203b562 100644 --- a/tests/tests-esm/unit/Footnote.test.js +++ b/tests/tests-esm/unit/Footnote.test.js @@ -1,10 +1,10 @@ import React from 'react'; import { render } from '@testing-library/react'; -import Footnote from '../../src/components/Footnote'; -import FootnoteContext from '../../src/components/Footnote/footnote-context'; +import Footnote from '../../../src/components/Footnote'; +import FootnoteContext from '../../../src/components/Footnote/footnote-context'; // data for this component -import mockData from './data/Footnote.test.json'; +import mockData from '../../unit/data/Footnote.test.json'; const mountFootnotes = (footnotes) => render( diff --git a/tests/tests-esm/unit/FootnoteReference.test.js b/tests/tests-esm/unit/FootnoteReference.test.js index b0ce994a5..1fd33e89c 100644 --- a/tests/tests-esm/unit/FootnoteReference.test.js +++ b/tests/tests-esm/unit/FootnoteReference.test.js @@ -1,9 +1,9 @@ import React from 'react'; import { render } from '@testing-library/react'; -import FootnoteReference from '../../src/components/Footnote/FootnoteReference'; +import FootnoteReference from '../../../src/components/Footnote/FootnoteReference'; // data for this component -import mockData from './data/FootnoteReference.test.json'; +import mockData from '../../unit/data/FootnoteReference.test.json'; it('renders correctly', () => { const tree = render(); diff --git a/tests/tests-esm/unit/GuideNext.test.js b/tests/tests-esm/unit/GuideNext.test.js index 2b5f9fca3..d6edf7ac2 100644 --- a/tests/tests-esm/unit/GuideNext.test.js +++ b/tests/tests-esm/unit/GuideNext.test.js @@ -1,11 +1,11 @@ import React from 'react'; // import { queryAllByRole } from '@testing-library/react'; import { render } from '@testing-library/react'; -import { mockLocation } from '../utils/mock-location'; -import GuideNext from '../../src/components/GuideNext'; -import * as browserStorage from '../../src/utils/browser-storage'; -import mockChaptersData from './data/Chapters.test.json'; -import mockNodeData from './data/GuideNext.test.json'; +import { mockLocation } from '../../utils/mock-location'; +import GuideNext from '../../../src/components/GuideNext'; +import * as browserStorage from '../../../src/utils/browser-storage'; +import mockChaptersData from '../../unit/data/Chapters.test.json'; +import mockNodeData from '../../unit/data/GuideNext.test.json'; const renderGuideNext = (slug, mockNodeData = {}) => { return render(); diff --git a/tests/tests-esm/unit/GuidesLandingTree.test.js b/tests/tests-esm/unit/GuidesLandingTree.test.js index e10af3a82..1ef447f14 100644 --- a/tests/tests-esm/unit/GuidesLandingTree.test.js +++ b/tests/tests-esm/unit/GuidesLandingTree.test.js @@ -1,8 +1,8 @@ import React from 'react'; import { render } from '@testing-library/react'; -import { mockLocation } from '../utils/mock-location'; -import GuidesLandingTree from '../../src/components/Sidenav/GuidesLandingTree'; -import mockData from './data/Chapters.test.json'; +import { mockLocation } from '../../utils/mock-location'; +import GuidesLandingTree from '../../../src/components/Sidenav/GuidesLandingTree'; +import mockData from '../../unit/data/Chapters.test.json'; const getWrapper = () => { const { chapters } = mockData.metadata; diff --git a/tests/tests-esm/unit/GuidesTOCTree.test.js b/tests/tests-esm/unit/GuidesTOCTree.test.js index c7eb2571a..8ea73e3c2 100644 --- a/tests/tests-esm/unit/GuidesTOCTree.test.js +++ b/tests/tests-esm/unit/GuidesTOCTree.test.js @@ -1,9 +1,9 @@ import React from 'react'; import { render } from '@testing-library/react'; -import { mockLocation } from '../utils/mock-location'; -import { ContentsContext } from '../../src/components/Contents/contents-context'; -import GuidesTOCTree from '../../src/components/Sidenav/GuidesTOCTree'; -import mockData from './data/Chapters.test.json'; +import { mockLocation } from '../../utils/mock-location'; +import { ContentsContext } from '../../../src/components/Contents/contents-context'; +import GuidesTOCTree from '../../../src/components/Sidenav/GuidesTOCTree'; +import mockData from '../../unit/data/Chapters.test.json'; const mockHeadingNodes = [ { id: 'heading1', title: 'Heading 1' }, diff --git a/tests/tests-esm/unit/Head.test.js b/tests/tests-esm/unit/Head.test.js index 4a975269b..6aacde6a9 100644 --- a/tests/tests-esm/unit/Head.test.js +++ b/tests/tests-esm/unit/Head.test.js @@ -1,13 +1,13 @@ import React from 'react'; import { render, screen } from '@testing-library/react'; -import { Head } from '../../src/components/DocumentBody'; -import mockStaticQuery from '../utils/mockStaticQuery'; -import { useSiteMetadata } from '../../src/hooks/use-site-metadata'; -import { usePathPrefix } from '../../src/hooks/use-path-prefix'; -import useSnootyMetadata from '../../src/utils/use-snooty-metadata'; -import mockCompleteEOLPageContext from './data/CompleteEOLPageContext.json'; -import mockEOLSnootyMetadata from './data/EOLSnootyMetadata.json'; -import mockHeadPageContext from './data/HeadPageContext.test.json'; +import { Head } from '../../../src/components/DocumentBody'; +import mockStaticQuery from '../../utils/mockStaticQuery'; +import { useSiteMetadata } from '../../../src/hooks/use-site-metadata'; +import { usePathPrefix } from '../../../src/hooks/use-path-prefix'; +import useSnootyMetadata from '../../../src/utils/use-snooty-metadata'; +import mockCompleteEOLPageContext from '../../unit/data/CompleteEOLPageContext.json'; +import mockEOLSnootyMetadata from '../../unit/data/EOLSnootyMetadata.json'; +import mockHeadPageContext from '../../unit/data/HeadPageContext.test.json'; jest.mock(`../../src/utils/use-snooty-metadata`, () => jest.fn()); diff --git a/tests/tests-esm/unit/Heading.test.js b/tests/tests-esm/unit/Heading.test.js index 6123e1192..7f66f0067 100644 --- a/tests/tests-esm/unit/Heading.test.js +++ b/tests/tests-esm/unit/Heading.test.js @@ -1,9 +1,9 @@ import React from 'react'; import { render } from '@testing-library/react'; -import Heading from '../../src/components/Heading'; +import Heading from '../../../src/components/Heading'; // data for this component -import mockData from './data/Heading.test.json'; +import mockData from '../../unit/data/Heading.test.json'; it('renders correctly', () => { const tree = render(); diff --git a/tests/tests-esm/unit/IA.test.js b/tests/tests-esm/unit/IA.test.js index 263137bf5..c116f11d7 100644 --- a/tests/tests-esm/unit/IA.test.js +++ b/tests/tests-esm/unit/IA.test.js @@ -1,10 +1,10 @@ import React from 'react'; import { render } from '@testing-library/react'; // Keep mockLocation on top to ensure mock is applied -import { mockLocation } from '../utils/mock-location'; -import IA from '../../src/components/Sidenav/IA'; -import useSnootyMetadata from '../../src/utils/use-snooty-metadata'; -import sampleData from './data/IA.test.json'; +import { mockLocation } from '../../utils/mock-location'; +import IA from '../../../src/components/Sidenav/IA'; +import useSnootyMetadata from '../../../src/utils/use-snooty-metadata'; +import sampleData from '../../unit/data/IA.test.json'; jest.mock(`../../src/utils/use-snooty-metadata`, () => jest.fn()); diff --git a/tests/tests-esm/unit/InternalPageNav.test.js b/tests/tests-esm/unit/InternalPageNav.test.js index 096058fc9..b0fae2575 100644 --- a/tests/tests-esm/unit/InternalPageNav.test.js +++ b/tests/tests-esm/unit/InternalPageNav.test.js @@ -1,8 +1,8 @@ import React from 'react'; import { render } from '@testing-library/react'; -import { mockLocation } from '../utils/mock-location'; -import InternalPageNav from '../../src/components/InternalPageNav'; -import slugTitleMapping from './data/ecosystem/slugTitleMapping.json'; +import { mockLocation } from '../../utils/mock-location'; +import InternalPageNav from '../../../src/components/InternalPageNav'; +import slugTitleMapping from '../../unit/data/ecosystem/slugTitleMapping.json'; const data = ['drivers/csharp', 'drivers/go', 'drivers/java']; diff --git a/tests/tests-esm/unit/Lightbox.test.js b/tests/tests-esm/unit/Lightbox.test.js index c2823c675..b298b4913 100644 --- a/tests/tests-esm/unit/Lightbox.test.js +++ b/tests/tests-esm/unit/Lightbox.test.js @@ -1,9 +1,9 @@ import React from 'react'; import { render } from '@testing-library/react'; import userEvent from '@testing-library/user-event'; -import Lightbox from '../../src/components/Figure/Lightbox'; +import Lightbox from '../../../src/components/Figure/Lightbox'; // data for this component -import mockData from './data/Figure.test.json'; +import mockData from '../../unit/data/Figure.test.json'; describe('Lightbox', () => { it('renders correctly', () => { diff --git a/tests/tests-esm/unit/Line.test.js b/tests/tests-esm/unit/Line.test.js index 366e0579c..ce3f3b76c 100644 --- a/tests/tests-esm/unit/Line.test.js +++ b/tests/tests-esm/unit/Line.test.js @@ -1,10 +1,10 @@ import React from 'react'; import { render } from '@testing-library/react'; -import Line from '../../src/components/LineBlock/Line'; +import Line from '../../../src/components/LineBlock/Line'; // data for this component -import mockData from './data/Line.test.json'; -import mockData2 from './data/Line-empty.test.json'; +import mockData from '../../unit/data/Line.test.json'; +import mockData2 from '../../unit/data/Line-empty.test.json'; it('renders correctly', () => { const tree = render(); diff --git a/tests/tests-esm/unit/LineBlock.test.js b/tests/tests-esm/unit/LineBlock.test.js index 8746241ce..a59bd7a9b 100644 --- a/tests/tests-esm/unit/LineBlock.test.js +++ b/tests/tests-esm/unit/LineBlock.test.js @@ -1,9 +1,9 @@ import React from 'react'; import { render } from '@testing-library/react'; -import LineBlock from '../../src/components/LineBlock'; +import LineBlock from '../../../src/components/LineBlock'; // data for this component -import mockData from './data/Literal.test.json'; +import mockData from '../../unit/data/Literal.test.json'; it('renders correctly', () => { const tree = render(); diff --git a/tests/tests-esm/unit/Link.test.js b/tests/tests-esm/unit/Link.test.js index 3e00b7e68..1d6f04841 100644 --- a/tests/tests-esm/unit/Link.test.js +++ b/tests/tests-esm/unit/Link.test.js @@ -1,7 +1,7 @@ import React from 'react'; import { render } from '@testing-library/react'; -import { mockLocation } from '../utils/mock-location'; -import Link from '../../src/components/Link'; +import { mockLocation } from '../../utils/mock-location'; +import Link from '../../../src/components/Link'; const setup = ({ text, ...rest }) => render({text}); diff --git a/tests/tests-esm/unit/List.test.js b/tests/tests-esm/unit/List.test.js index a8a084e05..37641cfec 100644 --- a/tests/tests-esm/unit/List.test.js +++ b/tests/tests-esm/unit/List.test.js @@ -1,9 +1,9 @@ import React from 'react'; import { render } from '@testing-library/react'; -import List from '../../src/components/List'; +import List from '../../../src/components/List'; // data for this component -import mockData from './data/List.test.json'; +import mockData from '../../unit/data/List.test.json'; it('List renders correctly', () => { const tree = render(); diff --git a/tests/tests-esm/unit/ListTable.test.js b/tests/tests-esm/unit/ListTable.test.js index 9d2660385..7abd6ebe8 100644 --- a/tests/tests-esm/unit/ListTable.test.js +++ b/tests/tests-esm/unit/ListTable.test.js @@ -1,10 +1,10 @@ import React from 'react'; import { render } from '@testing-library/react'; import { matchers } from '@emotion/jest'; -import ListTable from '../../src/components/ListTable'; +import ListTable from '../../../src/components/ListTable'; -import mockData from './data/ListTable.test.json'; -import mockDataFixedWidths from './data/ListTableFixedWidths.test.json'; +import mockData from '../../unit/data/ListTable.test.json'; +import mockDataFixedWidths from '../../unit/data/ListTableFixedWidths.test.json'; expect.extend(matchers); diff --git a/tests/tests-esm/unit/Literal.test.js b/tests/tests-esm/unit/Literal.test.js index 86ce1e031..8ba82dc8d 100644 --- a/tests/tests-esm/unit/Literal.test.js +++ b/tests/tests-esm/unit/Literal.test.js @@ -1,9 +1,9 @@ import React from 'react'; import { render } from '@testing-library/react'; -import Literal from '../../src/components/Literal'; +import Literal from '../../../src/components/Literal'; // data for this component -import mockData from './data/Literal.test.json'; +import mockData from '../../unit/data/Literal.test.json'; it('renders correctly', () => { const tree = render(); diff --git a/tests/tests-esm/unit/LiteralInclude.test.js b/tests/tests-esm/unit/LiteralInclude.test.js index 4494cfc89..f4dbe71ef 100644 --- a/tests/tests-esm/unit/LiteralInclude.test.js +++ b/tests/tests-esm/unit/LiteralInclude.test.js @@ -1,9 +1,9 @@ import React from 'react'; import { render } from '@testing-library/react'; -import LiteralInclude from '../../src/components/LiteralInclude'; +import LiteralInclude from '../../../src/components/LiteralInclude'; // data for this component -import mockData from './data/LiteralInclude.test.json'; +import mockData from '../../unit/data/LiteralInclude.test.json'; it('renders correctly', () => { const tree = render(); diff --git a/tests/tests-esm/unit/Meta.test.js b/tests/tests-esm/unit/Meta.test.js index dc0709814..dd0c2a67a 100644 --- a/tests/tests-esm/unit/Meta.test.js +++ b/tests/tests-esm/unit/Meta.test.js @@ -1,10 +1,10 @@ import React from 'react'; import { render, screen } from '@testing-library/react'; -import { getMetaFromDirective } from '../../src/utils/get-meta-from-directive'; -import Meta from '../../src/components/Meta'; +import { getMetaFromDirective } from '../../../src/utils/get-meta-from-directive'; +import Meta from '../../../src/components/Meta'; // data for this component -import { testPageNodes } from './data/MetaData'; +import { testPageNodes } from '../../unit/data/MetaData'; describe('Meta Tag', () => { it('does not renders a Meta correctly when the meta value is present', () => { diff --git a/tests/tests-esm/unit/OpenAPI.test.js b/tests/tests-esm/unit/OpenAPI.test.js index 6981684bc..92eaf31ed 100644 --- a/tests/tests-esm/unit/OpenAPI.test.js +++ b/tests/tests-esm/unit/OpenAPI.test.js @@ -1,6 +1,6 @@ import React from 'react'; import { render } from '@testing-library/react'; -import OpenAPI from '../../src/components/OpenAPI'; +import OpenAPI from '../../../src/components/OpenAPI'; const mockSpecJson = { openapi: '3.0.0', diff --git a/tests/tests-esm/unit/OpenAPIChangelog.test.js b/tests/tests-esm/unit/OpenAPIChangelog.test.js index ba3866d6f..9e0e13fd4 100644 --- a/tests/tests-esm/unit/OpenAPIChangelog.test.js +++ b/tests/tests-esm/unit/OpenAPIChangelog.test.js @@ -2,9 +2,9 @@ import React from 'react'; import * as Gatsby from 'gatsby'; import { render } from '@testing-library/react'; import userEvent from '@testing-library/user-event'; -import * as realm from '../../src/utils/realm'; -import OpenAPIChangelog from '../../src/components/OpenAPIChangelog'; -import { mockChangelog, mockDiff, mockIndex } from './data/OpenAPIChangelog'; +import * as realm from '../../../src/utils/realm'; +import OpenAPIChangelog from '../../../src/components/OpenAPIChangelog'; +import { mockChangelog, mockDiff, mockIndex } from '../../unit/data/OpenAPIChangelog'; /** * Helper function to strip HTML from combobox list options diff --git a/tests/tests-esm/unit/Paragraph.test.js b/tests/tests-esm/unit/Paragraph.test.js index 3c45f1a0d..862f99368 100644 --- a/tests/tests-esm/unit/Paragraph.test.js +++ b/tests/tests-esm/unit/Paragraph.test.js @@ -1,11 +1,11 @@ import React from 'react'; import { render } from '@testing-library/react'; -import { mockLocation } from '../utils/mock-location'; -import Paragraph from '../../src/components/Paragraph'; +import { mockLocation } from '../../utils/mock-location'; +import Paragraph from '../../../src/components/Paragraph'; // data for this component -import mockData from './data/Paragraph.test.json'; -import mockDataFormat from './data/Paragraph-Format.test.json'; +import mockData from '../../unit/data/Paragraph.test.json'; +import mockDataFormat from '../../unit/data/Paragraph-Format.test.json'; beforeAll(() => { mockLocation(null, `/`); diff --git a/tests/tests-esm/unit/Presentation.test.js b/tests/tests-esm/unit/Presentation.test.js index 7be190d7c..4d0cb6916 100644 --- a/tests/tests-esm/unit/Presentation.test.js +++ b/tests/tests-esm/unit/Presentation.test.js @@ -1,9 +1,9 @@ import React from 'react'; import { render, screen } from '@testing-library/react'; -import { mockLocation } from '../utils/mock-location'; -import DocumentBody from '../../src/components/DocumentBody'; -import mockPageContext from './data/PageContext.test.json'; -import mockSnootyMetadata from './data/SnootyMetadata.json'; +import { mockLocation } from '../../utils/mock-location'; +import DocumentBody from '../../../src/components/DocumentBody'; +import mockPageContext from '../../unit/data/PageContext.test.json'; +import mockSnootyMetadata from '../../unit/data/SnootyMetadata.json'; jest.mock(`../../src/utils/use-snooty-metadata`, () => { return () => mockSnootyMetadata; diff --git a/tests/tests-esm/unit/Procedure.test.js b/tests/tests-esm/unit/Procedure.test.js index 4762606ad..c69c137e5 100644 --- a/tests/tests-esm/unit/Procedure.test.js +++ b/tests/tests-esm/unit/Procedure.test.js @@ -1,10 +1,10 @@ import React from 'react'; import { render } from '@testing-library/react'; -import { mockLocation } from '../utils/mock-location'; -import Procedure from '../../src/components/Procedure'; +import { mockLocation } from '../../utils/mock-location'; +import Procedure from '../../../src/components/Procedure'; // data for this component -import mockData from './data/Procedure.test.json'; +import mockData from '../../unit/data/Procedure.test.json'; beforeAll(() => { mockLocation(null, `/`); diff --git a/tests/tests-esm/unit/ProductsList.test.js b/tests/tests-esm/unit/ProductsList.test.js index c4d4e827e..f8fd6a2dc 100644 --- a/tests/tests-esm/unit/ProductsList.test.js +++ b/tests/tests-esm/unit/ProductsList.test.js @@ -2,9 +2,9 @@ import React from 'react'; import { render } from '@testing-library/react'; import userEvent from '@testing-library/user-event'; import { matchers } from '@emotion/jest'; -import { mockLocation } from '../utils/mock-location'; -import ProductsList from '../../src/components/Sidenav/ProductsList'; -import { tick } from '../utils'; +import { mockLocation } from '../../utils/mock-location'; +import ProductsList from '../../../src/components/Sidenav/ProductsList'; +import { tick } from '../../utils'; const mockProducts = [ { diff --git a/tests/tests-esm/unit/QuizWidget.test.js b/tests/tests-esm/unit/QuizWidget.test.js index 1386740f9..539844e5d 100644 --- a/tests/tests-esm/unit/QuizWidget.test.js +++ b/tests/tests-esm/unit/QuizWidget.test.js @@ -1,9 +1,9 @@ import React from 'react'; import { render } from '@testing-library/react'; -import QuizWidget from '../../src/components/Widgets/QuizWidget/QuizWidget'; +import QuizWidget from '../../../src/components/Widgets/QuizWidget/QuizWidget'; // data for this component -import { completeQuiz, noQuestion } from './data/QuizWidget.test.json'; +import { completeQuiz, noQuestion } from '../../unit/data/QuizWidget.test.json'; const siteUrl = 'https://docs.mongodb.com'; const project = 'cloud-docs'; diff --git a/tests/tests-esm/unit/Reference.test.js b/tests/tests-esm/unit/Reference.test.js index 0ce0d3221..a772b57e5 100644 --- a/tests/tests-esm/unit/Reference.test.js +++ b/tests/tests-esm/unit/Reference.test.js @@ -1,10 +1,10 @@ import React from 'react'; import { render } from '@testing-library/react'; -import { mockLocation } from '../utils/mock-location'; -import Reference from '../../src/components/Reference'; +import { mockLocation } from '../../utils/mock-location'; +import Reference from '../../../src/components/Reference'; // data for this component -import mockData from './data/Reference.test.json'; +import mockData from '../../unit/data/Reference.test.json'; beforeAll(() => { mockLocation(null, `/`); diff --git a/tests/tests-esm/unit/ReleaseSpecification.test.js b/tests/tests-esm/unit/ReleaseSpecification.test.js index 92d00328b..a4e893423 100644 --- a/tests/tests-esm/unit/ReleaseSpecification.test.js +++ b/tests/tests-esm/unit/ReleaseSpecification.test.js @@ -1,9 +1,9 @@ import React from 'react'; import { render } from '@testing-library/react'; -import ReleaseSpecification from '../../src/components/ReleaseSpecification'; +import ReleaseSpecification from '../../../src/components/ReleaseSpecification'; // data for this component -import mockData from './data/ReleaseSpecification.test.json'; +import mockData from '../../unit/data/ReleaseSpecification.test.json'; it('renders correctly', () => { const tree = render(); diff --git a/tests/tests-esm/unit/Role.test.js b/tests/tests-esm/unit/Role.test.js index 6a2728ac5..3d52c517f 100644 --- a/tests/tests-esm/unit/Role.test.js +++ b/tests/tests-esm/unit/Role.test.js @@ -1,13 +1,13 @@ import React from 'react'; import { render } from '@testing-library/react'; -import RoleAbbr from '../../src/components/Roles/Abbr'; -import RoleGUILabel from '../../src/components/Roles/GUILabel'; -import RoleFile from '../../src/components/Roles/File'; +import RoleAbbr from '../../../src/components/Roles/Abbr'; +import RoleGUILabel from '../../../src/components/Roles/GUILabel'; +import RoleFile from '../../../src/components/Roles/File'; -import mockDataGUILabel from './data/Role-guilabel.test.json'; -import mockDataFile from './data/Role-file.test.json'; -import mockDataAbbr from './data/Role-abbr.test.json'; +import mockDataGUILabel from '../../unit/data/Role-guilabel.test.json'; +import mockDataFile from '../../unit/data/Role-file.test.json'; +import mockDataAbbr from '../../unit/data/Role-abbr.test.json'; describe('GUI Label', () => { it('correctly renders a "guilabel" role', () => { diff --git a/tests/tests-esm/unit/SearchResults.test.js b/tests/tests-esm/unit/SearchResults.test.js index 069bc1c25..43fb64572 100644 --- a/tests/tests-esm/unit/SearchResults.test.js +++ b/tests/tests-esm/unit/SearchResults.test.js @@ -5,14 +5,14 @@ import { render, within } from '@testing-library/react'; import userEvent from '@testing-library/user-event'; import { act } from 'react-dom/test-utils'; // Importing all specifically to use jest spyOn, mockImplementation for mocking -import { mockLocation } from '../utils/mock-location'; -import { tick, setMobile } from '../utils'; -import SearchResults from '../../src/components/SearchResults'; -import { SearchContextProvider } from '../../src/components/SearchResults/SearchContext'; -import mockStaticQuery from '../utils/mockStaticQuery'; -import * as RealmUtil from '../../src/utils/realm'; -import mockInputData from '../utils/data/marian-manifests.json'; -import { FILTERED_RESULT, mockMarianFetch, UNFILTERED_RESULT } from './utils/mock-marian-fetch'; +import { mockLocation } from '../../utils/mock-location'; +import { tick, setMobile } from '../../utils'; +import SearchResults from '../../../src/components/SearchResults'; +import { SearchContextProvider } from '../../../src/components/SearchResults/SearchContext'; +import mockStaticQuery from '../../utils/mockStaticQuery'; +import * as RealmUtil from '../../../src/utils/realm'; +import mockInputData from '../../utils/data/marian-manifests.json'; +import { FILTERED_RESULT, mockMarianFetch, UNFILTERED_RESULT } from '../../unit/utils/mock-marian-fetch'; const MOBILE_SEARCH_BACK_BUTTON_TEXT = 'Back to search results'; diff --git a/tests/tests-esm/unit/Section.test.js b/tests/tests-esm/unit/Section.test.js index 06c799bf0..fee5b7ee9 100644 --- a/tests/tests-esm/unit/Section.test.js +++ b/tests/tests-esm/unit/Section.test.js @@ -1,9 +1,9 @@ import React from 'react'; import { render } from '@testing-library/react'; -import Section from '../../src/components/Section'; +import Section from '../../../src/components/Section'; // data for this component -import mockData from './data/Section.test.json'; +import mockData from '../../unit/data/Section.test.json'; it('renders correctly', () => { const tree = render(
); diff --git a/tests/tests-esm/unit/Sidenav.test.js b/tests/tests-esm/unit/Sidenav.test.js index b25366ea7..b9649f999 100644 --- a/tests/tests-esm/unit/Sidenav.test.js +++ b/tests/tests-esm/unit/Sidenav.test.js @@ -2,10 +2,10 @@ import React from 'react'; import { render } from '@testing-library/react'; import userEvent from '@testing-library/user-event'; import { matchers } from '@emotion/jest'; -import { mockLocation } from '../utils/mock-location'; -import { Sidenav, SidenavContextProvider, SidenavMobileMenuButton } from '../../src/components/Sidenav'; -import { theme } from '../../src/theme/docsTheme'; -import { tick, setMatchMedia, setMobile } from '../utils'; +import { mockLocation } from '../../utils/mock-location'; +import { Sidenav, SidenavContextProvider, SidenavMobileMenuButton } from '../../../src/components/Sidenav'; +import { theme } from '../../../src/theme/docsTheme'; +import { tick, setMatchMedia, setMobile } from '../../utils'; jest.mock(`../../src/utils/use-snooty-metadata`, () => { return () => ({ project: 'test-project' }); diff --git a/tests/tests-esm/unit/SiteBanner.test.js b/tests/tests-esm/unit/SiteBanner.test.js index c2e868d68..4dbe6f181 100644 --- a/tests/tests-esm/unit/SiteBanner.test.js +++ b/tests/tests-esm/unit/SiteBanner.test.js @@ -1,10 +1,10 @@ import React from 'react'; import { render } from '@testing-library/react'; import * as Gatsby from 'gatsby'; -import * as RealmUtil from '../../src/utils/realm'; -import SiteBanner from '../../src/components/Banner/SiteBanner'; -import { HeaderContext } from '../../src/components/Header/header-context'; -import { tick } from '../utils'; +import * as RealmUtil from '../../../src/utils/realm'; +import SiteBanner from '../../../src/components/Banner/SiteBanner'; +import { HeaderContext } from '../../../src/components/Header/header-context'; +import { tick } from '../../utils'; const useStaticQuery = jest.spyOn(Gatsby, 'useStaticQuery'); const mockSnootyEnv = (snootyEnv) => { diff --git a/tests/tests-esm/unit/Step.test.js b/tests/tests-esm/unit/Step.test.js index 1984f4480..6b44b0113 100644 --- a/tests/tests-esm/unit/Step.test.js +++ b/tests/tests-esm/unit/Step.test.js @@ -1,10 +1,10 @@ import React from 'react'; import { render } from '@testing-library/react'; -import { mockLocation } from '../utils/mock-location'; -import Step from '../../src/components/Procedure/Step'; +import { mockLocation } from '../../utils/mock-location'; +import Step from '../../../src/components/Procedure/Step'; // data for this component -import mockData from './data/Step.test.json'; +import mockData from '../../unit/data/Step.test.json'; beforeAll(() => { mockLocation(null, `/`); diff --git a/tests/tests-esm/unit/Strong.test.js b/tests/tests-esm/unit/Strong.test.js index cedfbc059..37b84ebf9 100644 --- a/tests/tests-esm/unit/Strong.test.js +++ b/tests/tests-esm/unit/Strong.test.js @@ -1,9 +1,9 @@ import React from 'react'; import { render } from '@testing-library/react'; -import Strong from '../../src/components/Strong'; +import Strong from '../../../src/components/Strong'; // data for this component -import mockData from './data/Strong.test.json'; +import mockData from '../../unit/data/Strong.test.json'; it('renders correctly', () => { const tree = render(); diff --git a/tests/tests-esm/unit/Tabs.test.js b/tests/tests-esm/unit/Tabs.test.js index bed873a4d..e09329447 100644 --- a/tests/tests-esm/unit/Tabs.test.js +++ b/tests/tests-esm/unit/Tabs.test.js @@ -1,15 +1,15 @@ import React from 'react'; import { render } from '@testing-library/react'; import { ThemeProvider } from '@emotion/react'; -import Tabs from '../../src/components/Tabs'; -import { TabProvider } from '../../src/components/Tabs/tab-context'; -import { theme } from '../../src/theme/docsTheme'; +import Tabs from '../../../src/components/Tabs'; +import { TabProvider } from '../../../src/components/Tabs/tab-context'; +import { theme } from '../../../src/theme/docsTheme'; // data for this component -import mockDataPlatforms from './data/Tabs-platform.test.json'; -import mockDataLanguages from './data/Tabs-languages.test.json'; -import mockDataHidden from './data/Tabs-hidden.test.json'; -import mockDataAnonymous from './data/Tabs-anonymous.test.json'; +import mockDataPlatforms from '../../unit/data/Tabs-platform.test.json'; +import mockDataLanguages from '../../unit/data/Tabs-languages.test.json'; +import mockDataHidden from '../../unit/data/Tabs-hidden.test.json'; +import mockDataAnonymous from '../../unit/data/Tabs-anonymous.test.json'; const mountTabs = ({ mockData }) => { return render( diff --git a/tests/tests-esm/unit/Target.test.js b/tests/tests-esm/unit/Target.test.js index e643f5434..662790a06 100644 --- a/tests/tests-esm/unit/Target.test.js +++ b/tests/tests-esm/unit/Target.test.js @@ -1,10 +1,10 @@ import React from 'react'; import { render } from '@testing-library/react'; -import { mockLocation } from '../utils/mock-location'; -import Target from '../../src/components/Target'; +import { mockLocation } from '../../utils/mock-location'; +import Target from '../../../src/components/Target'; // data for this component -import mockData from './data/Target.test.json'; +import mockData from '../../unit/data/Target.test.json'; beforeAll(() => { mockLocation(null, `/`); diff --git a/tests/tests-esm/unit/Text.test.js b/tests/tests-esm/unit/Text.test.js index 4ba0ee462..727263188 100644 --- a/tests/tests-esm/unit/Text.test.js +++ b/tests/tests-esm/unit/Text.test.js @@ -1,9 +1,9 @@ import React from 'react'; import { render } from '@testing-library/react'; -import Text from '../../src/components/Text'; +import Text from '../../../src/components/Text'; // data for this component -import mockData from './data/Text.test.json'; +import mockData from '../../unit/data/Text.test.json'; it('renders correctly', () => { const tree = render(); diff --git a/tests/tests-esm/unit/Time.test.js b/tests/tests-esm/unit/Time.test.js index 70473f580..d913909ce 100644 --- a/tests/tests-esm/unit/Time.test.js +++ b/tests/tests-esm/unit/Time.test.js @@ -1,7 +1,7 @@ import React from 'react'; import { render } from '@testing-library/react'; -import Time from '../../src/components/Time'; -import mockData from './data/Time.test.json'; +import Time from '../../../src/components/Time'; +import mockData from '../../unit/data/Time.test.json'; it('renders correctly', () => { const wrapper = render(