Here are some different ways on how to set up Jest to support ESM. This applies for Jest v25, Node v13, and Babel v7.
Node v14 and Jest v26 support ESM natively with the --experimental-vm-modules
flag.
Install cross-env
:
// file located under: plugins/affected-build/index.mjs | |
/** @type {import('@netlify/build').OnPreBuild} */ | |
export const onPreBuild = async ({ utils }) => { | |
const prevCommitRef = process.env.CACHED_COMMIT_REF; | |
const currentCommitRef = process.env.COMMIT_REF; | |
const isInitialBuild = currentCommitRef === prevCommitRef; // check if it's the initial build | |
const projectName = process.env.PROJECT_NAME; // can be set through an env variable in the `netlify.toml` or UI. |
# Sources used in figuring this out: | |
# | |
# - https://developer.mozilla.org/en-US/docs/WebAssembly/C_to_wasm | |
# - https://emscripten.org/docs/compiling/Building-Projects.html#building-projects | |
# Set up Emscripten SDK | |
git clone https://github.com/emscripten-core/emsdk.git | |
cd emsdk/ | |
./emsdk install latest | |
./emsdk activate latest |
*[class], | |
*[id] { | |
position: relative; | |
outline: 2px dashed red; | |
} | |
*[class]::before, *[class]::after, | |
*[id]::before, | |
*[id]::after { | |
position: absolute; |
import fetch from 'node-fetch'; | |
import Twitter from 'twit'; | |
import { parse, format } from 'fecha'; | |
import { take } from 'ramda'; | |
const URL = 'GOOGLE_SHEETS_URL'; | |
const T = new Twitter({ | |
consumer_key: 'consumer_key', | |
consumer_secret: 'consumer_secret', |
exports.onCreateNode = ({ node, actions, createNodeId, createContentDigest }) => { | |
const { createNode, createNodeField } = actions | |
if (node.internal.type === `NodeTypeWithMarkdownField`) { | |
const newNode = createNode({ | |
id: createNodeId(`${node.id} markdown field`), | |
children: [], | |
parent: node.id, | |
internal: { | |
content: node.markdownField, | |
mediaType: `text/markdown`, |
'use strict'; | |
const pointsToFile = uri => /\/[^/]+\.[^/]+$/.test(uri); | |
exports.handler = (event, context, callback) => { | |
// Extract the request from the CloudFront event that is sent to Lambda@Edge | |
var request = event.Records[0].cf.request; | |
// Extract the URI from the request |
'use strict'; | |
const path = require('path') | |
const redirect = new_url => { | |
return { | |
status: '301', | |
statusDescription: 'Moved Permanently', | |
headers: { | |
location: [{ |