Skip to content

Commit

Permalink
fix(test): import assertions incompatible with GitHub Actions node
Browse files Browse the repository at this point in the history
release-npm
  • Loading branch information
tobua committed Jun 4, 2022
1 parent b486cd2 commit 60b0855
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
14 changes: 9 additions & 5 deletions configuration/cypress.config.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import { existsSync } from 'fs'
import { existsSync, readFileSync } from 'fs'
// eslint-disable-next-line import/no-extraneous-dependencies
import { defineConfig } from 'cypress'
import objectAssignDeep from 'object-assign-deep'
// eslint-disable-next-line import/no-unresolved
import packageJson from '../../../package.json' assert { type: 'json' }
import { log } from '../utility/helper.js'

const importFileContents = async (fileName, readableName) => {
Expand All @@ -12,7 +10,13 @@ const importFileContents = async (fileName, readableName) => {

if (existsSync(filePath)) {
try {
result = await import(filePath)
if (filePath.endsWith('.json')) {
// Dynamic import would either require assert which fails on older node versions
// or throws ERR_UNKNOWN_FILE_EXTENSION due to JSON on older < 16.15 node.
result = JSON.parse(readFileSync(filePath))
} else {
result = await import(filePath)
}
} catch (error) {
console.log(error)
log(`Failed to read ${readableName} from ${filePath}.`, 'warning')
Expand All @@ -32,6 +36,7 @@ const plugin = await importFileContents(
'cypress/plugins/index.cjs',
'package cypress configuration'
)
const packageJson = await importFileContents('package.json', 'package.json')

let packageJsonConfig = {}

Expand All @@ -45,7 +50,6 @@ const defaults = {
// We've imported your old cypress plugins here.
// You may want to clean this up later by importing these.
setupNodeEvents(on, config) {
console.log('setup', plugin)
return plugin && plugin(on, config)
},
},
Expand Down
1 change: 0 additions & 1 deletion configuration/eslint.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ module.exports = {
],
'@babel/react',
],
plugins: ['@babel/plugin-syntax-import-assertions'],
},
},
settings: customSettings,
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
"dependencies": {
"@babel/core": "^7.18.2",
"@babel/eslint-parser": "^7.18.2",
"@babel/plugin-syntax-import-assertions": "^7.17.12",
"@babel/preset-env": "^7.18.2",
"@babel/preset-react": "^7.17.12",
"@babel/preset-typescript": "^7.17.12",
Expand Down

0 comments on commit 60b0855

Please sign in to comment.