You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Since upgrading from beta.12 to beta.44, jest tests fail with a syntax error, as gatsby-browser-entry is not being processed through Babel. Previously, cache-dir was transpiled before publishing as a package, but this was changed recently. All my other settings are as before. My project is mostly TypeScript, with ts-jest, but .js files are configured to use babel-jest. The repo can be found here.
constsiteConfig=require("./site-config");module.exports={pathPrefix: siteConfig.pathPrefix,siteMetadata: siteConfig.siteMetadata,mapping: {"ProjectsJson.client": "ClientsJson"},plugins: [`gatsby-plugin-react-helmet`,{resolve: `gatsby-source-filesystem`,options: {path: `${__dirname}/static/assets`,name: "uploads"}},{resolve: `gatsby-source-filesystem`,options: {path: `${__dirname}/src/pages`,name: "pages"}},// This plugin identifies file nodes that are images and// transforms these to create new “ImageSharp” nodes.// With them you can resize images and// generate responsive image thumbnails.`gatsby-transformer-sharp`,// transform JSON file nodes`gatsby-transformer-json`,// This plugin exposes helper functions for processing// images with the NPM package “sharp”. It's used by// several plugins.`gatsby-plugin-sharp`,// Manifest for AppCache and PWA compatibility{resolve: `gatsby-plugin-manifest`,options: siteConfig.manifest},{resolve: `gatsby-plugin-netlify-cms`,options: {// One convention is to place your Netlify CMS customization code in a// `src/cms` directory.modulePath: `${__dirname}/src/cms/cms.ts`}},`gatsby-plugin-typescript`]};
constpath=require("path");const{ createFilePath }=require("gatsby-source-filesystem");constdeepMap=require("deep-map");// Implement the Gatsby API “createPages”. This is// called after the Gatsby bootstrap is finished so you have// access to any information necessary to programmatically// create pages.exports.createPages=({ actions, graphql })=>{const{ createPage }=actions;/** * Work out the necessary to generate disntinct pages * @param {object} edge - The data for the distinct page */constgenerateDistinctPage=data=>{consttemplate=data.path&&data.path.replace("/","");const{ id, sections, staff }=data;// for the time being we can just assume that there are different teplates for each of the pages, but we can add logic here to reuse page templatescreatePage({path: template,component: path.resolve(`src/templates/${String(template)}.tsx`),// additional data can be passed via contextcontext: {
id
}});};/** * * @param {string} id - JSON id, generally a path to the file * @param {string} template - the string name of the template without the `.tsx` * @param {string} slug - generally the unique name of the JSON file (without path or file type) */constgeneratePage=(id,template,slug)=>{createPage({path: slug,component: path.resolve(`src/templates/${String(template)}.tsx`),// additional data can be passed via contextcontext: {
id
}});};/** * Run queries to get all the types of pages for which we need to make static pages * * `allPagesJson` needs a bit more information if we want to control how they are * processed in the future */returngraphql(` { allProjectsJson(limit: 1000) { edges { node { id slug } } } allPagesJson(limit: 1000) { edges { node { id path staff { name } sections { title } } } } } `).then(result=>{if(result.errors){result.errors.forEach(e=>console.error(e.toString()));returnPromise.reject(result.errors);}// Gatsby uses Redux to manage its internal state.// Plugins and sites can use functions like "createPage"// to interact with Gatsby.result.data.allProjectsJson.edges.forEach(edge=>{constid=edge.node.id;consttemplate="project";constslug=`our-work/project/${edge.node.slug}`;generatePage(id,template,slug);});result.data.allPagesJson.edges.forEach(edge=>{generateDistinctPage(edge.node);});returnPromise.resolve();});};constexcluded=newSet(["internal","children","parent","id"]);exports.onCreateNode=({ node, getNode, getNodes })=>{if(node.internal.owner==="gatsby-transformer-json"){constparent=getNode(node.parent);constmakeRelative=value=>{if(typeofvalue==="string"){constpathToFile=path.join(__dirname,"static",value);constfoundFileNode=getNodes().find(n=>n.absolutePath===pathToFile);if(foundFileNode){constp=path.relative(parent.dir,foundFileNode.absolutePath);if(p){returnp;}}}returnvalue;};Object.keys(node).forEach(key=>{if(excluded.has(key)){return;}if(typeofnode[key]==="string"){node[key]=makeRelative(node[key]);}deepMap(node[key],makeRelative,{inPlace: true});});}};exports.onCreateWebpackConfig=({ actions, stage, loaders, getConfig },{ postCssPlugins, ...sassOptions})=>{constsassLoader={loader: require.resolve(`sass-loader`),options: {sourceMap: stage==="develop",
...sassOptions}};constcssLoader={loader: require.resolve("typings-for-css-modules-loader"),options: {modules: true,camelCase: true,banner: `/* tslint:disable */// This file is automatically generated from your CSS. Any edits will be overwritten.`,namedExport: true,silent: true,importLoaders: 2,localIdentName: "[path][name]__[local]--[hash:base64:5]"}};constsassModuleRule={test: /\.s(a|c)ss$/,use: [loaders.miniCssExtract(),cssLoader,loaders.postcss({plugins: [require("autoprefixer")({browsers: [">1%"]})]}),sassLoader]};letconfigRules=[];switch(stage){case`develop`:
case`build-html`:
case`develop-html`:
configRules.push(sassModuleRule);break;case`build-javascript`:
configRules=[sassModuleRule,{test: /\.mjs$/,include: /node_modules/,type: "javascript/auto"}];break;default:
return;}actions.setWebpackConfig({module: {rules: configRules},resolve: {extensions: [".webpack.js",".web.js",".mjs",".js",".json",".jsx",".ts",".tsx"]}});};
gatsby-browser.js: N/A gatsby-ssr.js: N/A
The text was updated successfully, but these errors were encountered:
OK, I've fixed this by putting a fuller babel config in the jest preprocessor. It would be nice to have a minimal jest setup either documented or included in the start projects, as it can be a bit of a fiddle to set up.
Yeah, that's definitely something we'd like. Do you think yours is a good starting point (now that you've gone through the pain of figuring things out)? Would you like to PR a start to a new docs page?
Description
Since upgrading from beta.12 to beta.44, jest tests fail with a syntax error, as gatsby-browser-entry is not being processed through Babel. Previously, cache-dir was transpiled before publishing as a package, but this was changed recently. All my other settings are as before. My project is mostly TypeScript, with ts-jest, but .js files are configured to use babel-jest. The repo can be found here.
Steps to reproduce
Run jest
Expected result
Tests pass as before
Actual result
Jest fails on non-transpiled gatsby code:
Environment
System:
OS: macOS High Sierra 10.13.4
CPU: x64 Intel(R) Core(TM) i7-7660U CPU @ 2.50GHz
Shell: 5.3 - /bin/zsh
Binaries:
Node: 9.11.1 - /usr/local/bin/node
Yarn: 1.7.0 - /usr/local/bin/yarn
npm: 6.1.0 - /usr/local/bin/npm
Browsers:
Chrome: 67.0.3396.99
Safari: 11.1
npmPackages:
gatsby: 2.0.0-beta.44 => 2.0.0-beta.44
gatsby-image: ^2.0.0-beta.6 => 2.0.0-beta.6
gatsby-plugin-manifest: ^2.0.2-beta.2 => 2.0.2-beta.2
gatsby-plugin-netlify-cms: ^2.0.0-beta.6 => 2.0.0-beta.6
gatsby-plugin-offline: next => 2.0.0-beta.2
gatsby-plugin-react-helmet: ^3.0.0-beta.3 => 3.0.0-beta.3
gatsby-plugin-sass: ^2.0.0-beta.5 => 2.0.0-beta.5
gatsby-plugin-sharp: ^2.0.0-beta.5 => 2.0.0-beta.5
gatsby-plugin-typescript: ^2.0.0-beta.5 => 2.0.0-beta.5
gatsby-source-filesystem: ^2.0.1-beta.5 => 2.0.1-beta.5
gatsby-transformer-json: ^2.1.1-beta.2 => 2.1.1-beta.2
gatsby-transformer-sharp: ^2.1.1-beta.5 => 2.1.1-beta.5
npmGlobalPackages:
gatsby-cli: 2.0.0-beta.6
File contents (if changed)
gatsby-config.js
:package.json
:gatsby-node.js
:gatsby-browser.js
: N/Agatsby-ssr.js
: N/AThe text was updated successfully, but these errors were encountered: