updated Ava configuration using babel - node.js

We have recently updated from ava 0.17.0 to version 2.4.0. The old configuration in the package.json no longer works and ava tests now fail.
the old configuration in our package.json looks like the following
"ava": {
"timeout": "10m",
"files": [
"app//*Spec.js",
"lib//*Spec.js",
"*Spec.js"
],
"source": [
"**/*.{js,jsx}"
],
"babel": {
"presets": [
[
"env",
{
"targets": {
"node": "current"
}
}
]
]
}
},
Can someone please tell me what is the new configuration required for ava 2.4.0....?

Possibly you need to wrap the current babel value in a "testOptions" object, e.g. "babel": { "testOptions": { "presets": … } }. Hard to say more without seeing your errors.

Related

Eslint ProjectNotFoundError

I am getting following when running eslint in a Gatsby project
Oops! Something went wrong! :(
ESLint: 7.32.0
[ProjectNotFoundError: File '/home/path_to_project/somefile.ts' doesn't match any project] {
name: 'ProjectNotFoundError',
message: "File '/home/path_to_project/somefile.ts' doesn't match any project"
}
My .eslintrc
{
"extends": [
"react-app",
"plugin:jsx-a11y/recommended",
"prettier",
"plugin:tailwindcss/recommended"
// "airbnb"
],
"plugins": ["jsx-a11y"],
"rules": {
"no-restricted-imports": [
"error",
{
"patterns": ["#/features/*/*"]
}
],
"tailwindcss/classnames-order": "error",
"tailwindcss/no-custom-classname": "error"
},
"settings": {
"tailwindcss": {
"groupByResponsive": true
}
},
"overrides": [
{
"files": ["*.ts", "*.tsx"],
"processor": "#graphql-eslint/graphql",
"parser": "#typescript-eslint/parser",
"extends": [
"eslint:recommended",
"plugin:#typescript-eslint/recommended"
],
"env": {
"es6": true
}
},
{
"files": ["*.graphql"],
"parser": "#graphql-eslint/eslint-plugin",
"plugins": ["#graphql-eslint"],
"rules": {
"#graphql-eslint/no-anonymous-operations": "error",
"#graphql-eslint/naming-convention": [
"error",
{
"OperationDefinition": {
"style": "PascalCase",
"forbiddenPrefixes": ["Query", "Mutation", "Subscription", "Get"],
"forbiddenSuffixes": ["Query", "Mutation", "Subscription"]
}
}
]
}
}
]
}
.eslintignore
node_modules/
.cache/
public/
.idea/
yarn-error.log
.yarn/
Commenting out the following section in .eslintrc fix the issue, but I want to keep that section, things used to work fine with that section before. No clue what's wrong, since the error message provided by ESLint is pretty vague.
{
"files": ["*.ts", "*.tsx"],
"processor": "#graphql-eslint/graphql",
"parser": "#typescript-eslint/parser",
"extends": [
"eslint:recommended",
"plugin:#typescript-eslint/recommended"
],
"env": {
"es6": true
}
},
Update
Problem seems to be due to following, since commenting it out fix the error.
"processor": "#graphql-eslint/graphql",
I was earlier using Gatsby's GraphQL Typegen disabled due to it buggy nature (rebuild loop and .cache errors) by commenting out graphql.config.js and removing graphqlTypegen: true, from gatsby-config.ts
According to graphql-eslint
If you are defining GraphQL schema or GraphQL operations in code files, you'll want to define an additional override to extend the functionality of this plugin to the schema and operations in those files.
{
"overrides": [
+ {
+ "files": ["*.js"],
+ "processor": "#graphql-eslint/graphql"
+ },
...
}
It seems, disabling GraphQL Typegen result in mentioned error in "processor": "#graphql-eslint/graphql" of eslint override.

Can't find Application entry file './main.js' in electron build

I have an electron app and I got this error when run electron-builder build.
Error: Application entry file "main.js" in the "/project/dist/release/mac/demo.app/Contents/Resources/app.asar" does not exist. Seems like a wrong configuration.
This is package.json. I have set the main to dist/electron.js but I don't understand why it keep saying main.js doesn't exist.
...
"main": "dist/electron.js",
"build": {
"productName": "demo",
"appId": "com.auspost.pos",
"files": [
"dist/",
"node_modules/**/*",
"package.json",
"dist/electron.js"
],
"directories": {
"output": "dist/release"
},
"dmg": {
"contents": [
{
"x": 130,
"y": 220
},
{
"x": 410,
"y": 220,
"type": "link",
"path": "/Applications"
}
]
},
"win": {
"target": [
"nsis",
"msi"
],
"icon": "./electron/assets/icons/win/app.ico"
},
"publish": {
"provider": "github"
}
},
...
"devDepencencies": {
"electron": "^5.0.2",
"electron-builder": "^20.41.0",
"electron-webpack": "^2.6.2",
}
Finally figure out that because the project has electron-webpack dependency which works as a base template for electron build configuration. There are some fields are defined there which get extended.
The fix for that is either remove electron-webpack from your project dependencies or use electron-webpack convention to manage your project.
I had a similar issue:
Application entry file "index.js" in the ".....\dist\win-unpacked\resources\app.asar" does not exist.
The fix for me was to add
main: "main.js"
in the package.json of the generated app, so .\app\package.json.
Seems like without this electron-builder 21 (electron 6) is looking for a "index.js" file.
I encountered the error when selecting the production version of my entry file which was in a different folder than the source production file.
Here is the relevant config section that got my app to build:
"build": {
"files": [
"electron-settings.json",
"package.json"
],
"extraResources": [
{
"from": "../build/backend/min",
"to": "app",
"filter": [
"**/*"
]
},
{
"from": "desktop/node_modules",
"to": "node_modules"
}
],
"mac": {
"extraResources": [
{
"from": "build/osx",
"to": "app/build/osx"
}
]
}
}

Can't make Parcel + Babel 7 + Jest work together

I have a problem with making Parcel, Jest and Babel work with the same .babelrc
Parcel version: 1.11.0
Jest version: 24.0.0
Node: v10.5.0
Platform: Win 10
.babelrc
{
"env": {
"development": {
"plugins": [
[
"#babel/plugin-transform-runtime",
{
"corejs": 2
}
]
]
},
"test": {
}
},
}
If I move the plugins section to the root of the JSON it works correctly with the web app, however Parcel or Babel for some reason can't recognize the development env even if I set it in the command line.
If run the tests without the environment setup (having the env as above) then I get
({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){import _Promise from "#babel/runtime-corejs2/core-js/promise";
with Jest.
Probably the test setup wouldn't get recognized either, it just works without the babel/plugin-transform-runtime
Using this .babelrc solved it:
{
"env": {
"production": {
"plugins": [
[
"#babel/plugin-transform-runtime",
{
"corejs": 2
}
]
]
},
"development": {
"plugins": [
[
"#babel/plugin-transform-runtime",
{
"corejs": 2
}
]
]
},
"test": {
"plugins": [
]
}
},
}

Error with ES6 Imports with Jest and Parcel

I have a project using react-parcel-app as a template, and I'm trying to integrate Jest but I'm having the following error.
Details:
/home/papaponmx/Projects/prime/src/actions/goals.spec.js:1
({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){import { addGoal } from './goals.mjs';
This is what my .babelrc looks like.
{
"presets": [
[
"env",
{"modules": false},
{
"targets": {
"browsers": [
"last 2 versions"
]
}
}
],
"react"
],
"plugins": [
"transform-class-properties",
"transform-object-rest-spread"
],
"env": {
"testing": {
"presets": ["es2015", "stage-1", "react" ],
"plugins": [
"lodash",
"transform-runtime",
"transform-es2015-modules-commonjs",
"dynamic-import-node"
]
}
}
}
I understand that parcel is supposed to support ES Modules without configuration, but I don't get the test import s to work.
Here is the link to the repo in case you want to run it locally.
By the help of this article i come to a solution using babel.
Install these packages as dev dependencies:
npm i --save-dev babel-jest #babel/core #babel/preset-env
In the root level of your project, create a .babelrc file and add the following:
{presets:["#babel/preset-env"]}
Then you can use ES6 imports in your test files

Why are my test files not being transpiled?

I have a suite of tests are being run with jest.
- initFromProgressObject.test.js
- nodeifyProgressObject.test.js
- segments.test.js
- uuid.test.js
- volume.progress.test.js
- volume.segment.test.js
The command i use to run the tests is jest --notify. Here is the error I get in just 2 of the files:
/Users/bob/Developer/sedd/sedd-utils/src/tests/uuid.test.js:1
({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){import * as uuid from "../utils/uuid";
^^^^^^
SyntaxError: Unexpected token import
All of the files are using import, but only 2 of them are having this issue of Unexpected token import. On another question, I saw that it was important to set the env to test. I have tried that and it didn't change anything.
Here is my .babelrc:
{
"env": {
"es": {
"presets": [
[
"env",
{
"targets": {
"browsers": ["last 2 versions"],
"node": "current"
},
"modules": false
}
]
],
"ignore": ["**/*.test.js", "**/tests/*"]
},
"test": {
"presets": ["env"]
},
"cjs": {
"presets": [
[
"env",
{
"targets": {
"browsers": ["last 2 versions"],
"node": "current"
}
}
]
],
"ignore": ["**/*.test.js", "**/tests/*"]
}
}
}
The jest config is just the default.
Any ideas?

Resources