Skip to content

Commit

Permalink
chore: add pull-configs
Browse files Browse the repository at this point in the history
  • Loading branch information
stagas committed Jan 22, 2022
1 parent ecbf214 commit 365396f
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 1 deletion.
17 changes: 17 additions & 0 deletions .pull-configs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const { pullConfigs } = require('pull-configs')

const local = __dirname + '/'
const remote = 'https://github.com/stagas/typescript-minimal-template/raw/main/'

const { assign, omit, sort, merge, replace } = pullConfigs(remote, local)

merge('package.json', (prev, next) => {
assign(prev.scripts, omit(next.scripts, ['build:min', 'test']))
sort(assign(prev.devDependencies, next.devDependencies))
})
replace('.eslintrc.js')
replace('.prettierrc')
replace('jest.config.js')
replace('tsconfig.json')
replace('web-test-runner.config.js')
merge('.vscode/settings.json')
42 changes: 42 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
module.exports = {
testEnvironment: 'jsdom', // or node
rootDir: '.',
roots: ['<rootDir>/test/', '<rootDir>/src'],
testMatch: ['**/*.spec.{js,jsx,ts,tsx}'],
testPathIgnorePatterns: ['<rootDir>/node_modules/', '<rootDir>/test/web/'],
coverageDirectory: '<rootDir>/coverage',
collectCoverageFrom: ['src/**/*.{ts,tsx}'],
coverageProvider: 'v8',

// enable this for real typescript builds (slow but accurate)
// preset: 'ts-jest',

// enable this for fast, correct sourcemaps but not all features supported
transform: {
'\\.(js|jsx|ts|tsx)$': [
'@stagas/sucrase-jest-plugin',
{
jsxPragma: 'h',
jsxFragmentPragma: 'Fragment',
production: true,
disableESTransforms: true,
},
],
},

// enable this for fast, incorrect sourcemaps but more features supported

// transform: {
// '\\.(js|jsx|ts|tsx)$': [
// '@swc-node/jest',
// {
// experimentalDecorators: true,
// emitDecoratorMetadata: true,
// react: {
// pragma: 'h',
// pragmaFrag: 'Fragment',
// },
// },
// ],
// },
}
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"prepack": "npm run clean && npm run build",
"prepack:dry": "npm pack --dry-run",
"prepush": "npm run lint && npm run test",
"prepare": "husky install"
"prepare": "husky install && node .pull-configs.js"
},
"devDependencies": {
"@n1kk/intspector": "^1.0.2",
Expand All @@ -72,6 +72,7 @@
"jest-browser-globals": "^25.1.0-beta",
"onchange": "^7.1.0",
"prettier": "^2.5.1",
"pull-configs": "^0.1.1",
"rimraf": "^3.0.2",
"terser": "^5.10.0",
"ts-jest": "^27.1.3",
Expand Down
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"moduleResolution": "node",
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"resolveJsonModule": true,
"isolatedModules": true,
"inlineSources": true,
"declaration": true,
Expand Down
35 changes: 35 additions & 0 deletions web-test-runner.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
const { esbuildPlugin } = require('@web/dev-server-esbuild')
const { summaryReporter } = require('@web/test-runner')
const { fromRollup } = require('@web/dev-server-rollup')
const rollupCommonjs = require('@rollup/plugin-commonjs')

const commonjs = fromRollup(rollupCommonjs);

module.exports = {
concurrency: 1,
nodeResolve: true,
files: ['test/**/*.spec.web.{ts,tsx}'],
plugins: [
esbuildPlugin({
ts: true,
tsx: true,
jsxFactory: 'h',
jsxFragment: 'Fragment',
}),
commonjs(),
],
reporters: [
summaryReporter(),
],
coverageConfig: {
include: ['src/**/*.{ts,tsx}'],
},
testRunnerHtml: testFramework => `
<html>
<head>
<script type="module" src="${testFramework}"></script>
<script type="module">import 'jest-browser-globals';</script>
</head>
</html>
`,
}

0 comments on commit 365396f

Please sign in to comment.