Skip to content

Commit

Permalink
feat: add global test framework and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
alanshaw committed Sep 15, 2022
1 parent 040927a commit c806db3
Show file tree
Hide file tree
Showing 10 changed files with 2,176 additions and 237 deletions.
2 changes: 2 additions & 0 deletions .github/actions/test/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ runs:
cache: 'npm'
- run: npm ci
shell: bash
- run: npm run lint
shell: bash
- run: npm run compile
shell: bash
- run: npm run build
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
node_modules
build
coverage
node_modules
10 changes: 9 additions & 1 deletion babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,13 @@ module.exports = {
],
'@babel/preset-typescript',
'@babel/preset-react'
]
],
env: {
test: {
plugins: [
// everything needs to be cjs for jest
['@babel/plugin-transform-modules-commonjs', { loose: true, importInterop: 'node' }]
]
}
}
}
30 changes: 30 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
const path = require('path')
const { lstatSync, readdirSync } = require('fs')

// get listing of packages in the mono repo
const basePath = path.resolve(__dirname, 'packages')
const packages = readdirSync(basePath)
.filter((name) => {
return lstatSync(path.join(basePath, name)).isDirectory()
})
.sort((a, b) => b.length - a.length)

// node_modules that need babel transform e.g. because not export cjs
const esmodules = ['@ipld/unixfs', 'actor'].join('|')

module.exports = {
collectCoverage: true,
coverageReporters: ['json', 'lcov', 'text', 'clover', 'text-summary'],
projects: packages.map((d) => ({
displayName: d,
clearMocks: true,
// testEnvironment: 'jsdom',
testEnvironment: './jest.env.js',
testMatch: [`<rootDir>/packages/${d}/**/*.test.[jt]s?(x)`],
// setupFilesAfterEnv: ['<rootDir>/jest.setup.js'],
snapshotFormat: {
printBasicPrototype: false
},
transformIgnorePatterns: [`/node_modules/(?!${esmodules})`]
}))
}
18 changes: 18 additions & 0 deletions jest.env.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const JSDOMEnvironment = require('jest-environment-jsdom')
const { TransformStream } = require('stream/web')
const { Blob, File } = require('@web-std/file')

// Extends the default JSDOMEnvironment to add globals that are present in all
// browsers and NodeJS that have not yet been added to the jsdom environment.
module.exports = class extends JSDOMEnvironment {
constructor (config, options) {
super(config, options)
Object.assign(this.global, {
TextEncoder,
TextDecoder,
TransformStream,
Blob,
File
})
}
}
Loading

0 comments on commit c806db3

Please sign in to comment.