Skip to content

Commit

Permalink
Merge pull request #13 from marko-js/modernize
Browse files Browse the repository at this point in the history
feat: add support for jest 27

BREAKING CHANGE: drop support for using @marko/jest as a preset which was deprecated (use @marko/preset/browser or @marko/preset/node)

BREAKING CHANGE: drop support node 12
  • Loading branch information
DylanPiercey authored Jun 2, 2021
2 parents 5cf6313 + 44f1213 commit 24130fe
Show file tree
Hide file tree
Showing 32 changed files with 7,623 additions and 5,421 deletions.
5 changes: 5 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.vscode
node_modules
coverage
dist
__snapshots__
31 changes: 31 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"root": true,
"extends": ["eslint:recommended", "prettier"],
"parserOptions": {
"sourceType": "module",
"impliedStrict": true
},
"env": {
"jest": true,
"node": true,
"es2020": true,
"browser": true
},
"overrides": [
{
"files": ["**/*.ts"],
"parser": "@typescript-eslint/parser",
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"prettier"
],
"rules": {
"@typescript-eslint/explicit-module-boundary-types": "off",
"@typescript-eslint/no-non-null-assertion": "off",
"@typescript-eslint/no-empty-function": "off",
"@typescript-eslint/no-explicit-any": "off"
}
}
]
}
3 changes: 3 additions & 0 deletions .fixpackrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"quiet": true
}
30 changes: 30 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: CI

on:
pull_request:
paths-ignore: ["**.md"]
push:
branches: ["main"]
paths-ignore: ["**.md"]

jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
node: [14.x, 16.x]
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Use node@${{ matrix.node }}
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node }}
- name: Install dependencies
run: npm ci
- name: Lint code
run: npm run lint
- name: Run tests
run: npm run ci:test
- name: Report code coverage
run: npm run ci:report
7 changes: 2 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,9 @@
npm-debug.log

# Build
/transform
/preset
dist
*.tsbuildinfo

# Coverage
coverage
.nyc_output

# Test
*.actual.*
1 change: 1 addition & 0 deletions .husky/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
_
6 changes: 0 additions & 6 deletions .huskyrc

This file was deleted.

4 changes: 0 additions & 4 deletions .lintstagedrc

This file was deleted.

4 changes: 4 additions & 0 deletions .lintstagedrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"*.ts": ["eslint -f codeframe --fix", "prettier --write"],
"*{.js,.json,.md,.yml,rc}": ["prettier --write"]
}
6 changes: 2 additions & 4 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
.vscode
.nyc_output
package.json
package-lock.json
CHANGELOG.md
node_modules
coverage
/preset
/transform
*.actual.*
dist
__snapshots__
10 changes: 10 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"overrides": [
{
"files": "*rc",
"options": {
"parser": "json"
}
}
]
}
11 changes: 0 additions & 11 deletions .travis.yml

This file was deleted.

2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2018 eBay Inc. and contributors
Copyright (c) 2021 eBay Inc. and contributors

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
23 changes: 12 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,20 @@ Templates are automatically compiled for the correct environment based on your J
```console
npm install @marko/jest -D
```

or

```console
yarn add @marko/jest -D
```


# Examples

**jest.config.js**

```javascript
module.exports = {
preset: "@marko/jest/preset/browser"
preset: "@marko/jest/preset/browser",
};
```

Expand Down Expand Up @@ -86,8 +87,8 @@ Jest presets are extensible by default, meaning you should be able to continue t
module.exports = {
preset: "@marko/jest/preset/browser",
transform: {
"\\.ts$": "ts-jest"
}
"\\.ts$": "ts-jest",
},
};
```

Expand All @@ -96,11 +97,11 @@ You can also get access to the preset configuration manually by importing `@mark
```javascript
const markoJest = require("@marko/jest/preset/browser/jest-preset");
module.exports = {
transform: markoJest.transform,
transformIgnorePatterns: markoJest.transformIgnorePatterns,
resolver: markoJest.resolver,
transform: markoJest.transform,
testEnvironment: markoJest.testEnvironment,
moduleFileExtensions: markoJest.moduleFileExtensions,
browser: true
transformIgnorePatterns: markoJest.transformIgnorePatterns,
};
```

Expand All @@ -116,14 +117,14 @@ module.exports = {
{
displayName: "browser",
preset: "@marko/jest/preset/browser",
testMatch: ["**/__tests__/**/*.browser.js"]
testMatch: ["**/__tests__/**/*.browser.js"],
},
{
displayName: "server",
preset: "@marko/jest/preset/node",
testMatch: ["**/__tests__/**/*.server.js"]
}
]
testMatch: ["**/__tests__/**/*.server.js"],
},
],
};
```

Expand Down
24 changes: 24 additions & 0 deletions build.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
const fs = require("fs");
const glob = require("tiny-glob");
const { build } = require("esbuild");

(async () => {
await fs.promises.rmdir("dist", { recursive: true }).catch(() => {});

// Ideally we'd use the same bundling / codesplitting as esm for cjs,
// but thats not yet possible with esbuild, so we manually build each file.
// https://github.com/evanw/esbuild/issues/1341
await build({
format: "cjs",
outdir: "dist",
platform: "node",
target: ["node14"],
entryPoints: await glob("src/{preset,transform}/**/*.ts"),
});
})().catch((err) => {
if (!err.errors) {
console.error(err);
}

process.exit(1);
});
25 changes: 0 additions & 25 deletions jest-preset.js

This file was deleted.

27 changes: 12 additions & 15 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,21 @@
const base = {
const common = {
transform: {
"\\.ts$": "ts-jest",
"\\.css$": "jest-transform-css"
}
"\\.ts$": "esbuild-jest",
"\\.css$": "jest-transform-css",
},
};

module.exports = {
projects: [
{
...base,
preset: "./preset/node/jest-preset.js",
displayName: "node",
testEnvironment: "node",
testMatch: ["<rootDir>/test/server.test.ts"]
...common,
preset: "./src/preset/node/jest-preset.ts",
testMatch: ["<rootDir>/test/server.test.ts"],
},
{
...base,
preset: "./preset/browser/jest-preset.js",
displayName: "browser",
testMatch: ["<rootDir>/test/browser.test.ts"]
}
]
...common,
preset: "./src/preset/browser/jest-preset.ts",
testMatch: ["<rootDir>/test/browser.test.ts"],
},
],
};
Loading

0 comments on commit 24130fe

Please sign in to comment.