-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
バックエンドのlintを導入 #2
Comments
swcをインストール npm i -D @swc/cli @swc/core |
Jestを導入する# インストール
npm install --save-dev jest @types/jest ts-jest
added 247 packages, and audited 430 packages in 14s
65 packages are looking for funding
run `npm fund` for details
found 0 vulnerabilities
# 初期化
npx ts-jest config:init
Jest configuration written to "/Users/opm006712/git/github.com/op-tennis/Practice-Backend/jest.config.js". npm test
> app@1.0.0 test
> jest
console.log
Hello, world!
at Object.<anonymous> (src/app.ts:1:9)
PASS test/sum.test.ts
✓ adds 1 + 2 to equal 3 (1 ms)
Test Suites: 1 passed, 1 total
Tests: 1 passed, 1 total
Snapshots: 0 total
Time: 0.72 s
Ran all test suites. |
swc はjestより早いらしいので、jestからswc/jestに変更する @swc/jestnpm i -D @swc/cli @swc/core touch jest.config.js const fs = require('fs')
const config = JSON.parse(fs.readFileSync(`${__dirname}/.swcrc`, 'utf-8'))
module.exports = {
transform: {
'^.+\\.(t|j)sx?$': ['@swc/jest', { ...config, /* custom configuration in Jest */ }],
},
} |
👆 公式を使う方法はうまくいかんので、Qiitaの記事を参考にする npx swc ./src/app.ts
Successfully compiled 1 file with swc.
console.log("Hello, world!");
export function sum(a, b) {
return a + b;
} index.js をこのように書いたconst swc = require("@swc/core");
// 第一引数には対象のソースコードを与えます。
// 第二引数には対象のコードが書かれたファイル名やsourcemapを作成することやminifyを行うか否かなどの設定を書きます。
// jscはswcの設定です。結果はPromise<Output>が返されます。このように作成したファイルをnode index.jsで実行するとトランスパイルされたファイルと結果が得られます。
swc
.transform("src/app.ts", {
filename: 'app.ts',
sourceMaps: true,
minify: true,
jsc: {
parser: {
syntax: "ecmascript",
},
transform: {},
minify: {
compress: {
unused: true
},
mangle: true,
},
},
})
.then((output) => {
console.log(output);
}
);
// 第一引数には対象のソースコードを与えます。
// 第二引数には設定を記述します。
swc
.parse("src/app.ts", {
syntax: "ecmascript",
comments: false,
script: true,
target: "es2022",
})
.then((module) => {
console.log(module);
console.log(module.body[0]);
}
); 実行結果👇 node index.js
{
type: 'Module',
span: { start: 1, end: 11, ctxt: 0 },
body: [
{
type: 'ExpressionStatement',
span: [Object],
expression: [Object]
}
],
interpreter: null
}
{
type: 'ExpressionStatement',
span: { start: 1, end: 11, ctxt: 0 },
expression: {
type: 'BinaryExpression',
span: { start: 1, end: 11, ctxt: 0 },
operator: '/',
left: {
type: 'Identifier',
span: [Object],
value: 'src',
optional: false
},
right: {
type: 'MemberExpression',
span: [Object],
object: [Object],
property: [Object]
}
}
}
{
code: 'src,app.ts;',
map: '{"version":3,"sources":["app.ts"],"sourcesContent":["src/app.ts"],"names":["src","app","ts"],"rangeMappings":"","mappings":"AAAAA,IAAIC,IAAIC,EAAE"}'
} |
・npm testを実行時にテストが失敗する ・ts-jestの時からソースコードに差分がほぼ無いのに落ちている理由がわからない
console.log("Hello, world!")
export function sum(a:any, b:any) {
return a + b;
} 型定義をするとエラーが出るが、下記のように型定義がされていないと成功する console.log("Hello, world!")
export function sum(a, b) {
return a + b;
} npm test
> app@1.0.0 test
> jest
console.log
Hello, world!
at Object.log (src/app.ts:1:9)
PASS test/sum.test.ts
✓ adds 1 + 2 to equal 3 (1 ms)
Test Suites: 1 passed, 1 total
Tests: 1 passed, 1 total
Snapshots: 0 total
Time: 0.121 s
Ran all test suites. |
COPILTくんに聞いてみた
エラーメッセージから見るに、 解決策としては、以下の手順を試してみてください: 1. module.exports = {
transform: {
'^.+\\.(t|j)sx?$': '@swc/jest',
},
} 2. {
"$schema": "https://json.schemastore.org/swcrc",
"jsc": {
"parser": {
"syntax": "typescript",
"dynamicImport": false,
"decorators": false
},
"target": "es2022",
"loose": false,
"externalHelpers": false
},
"minify": false
}
これらの手順を試してみて、それでも問題が解決しない場合は、詳しい情報を教えていただければと思います。よろしくお願いいたします。🙏 ソース: Bing との会話 2024/5/12 |
macOS Download # Create a folder
$ mkdir actions-runner && cd actions-runner
# Download the latest runner package
$ curl -o actions-runner-osx-arm64-2.316.1.tar.gz -L https://github.com/actions/runner/releases/download/v2.316.1/actions-runner-osx-arm64-2.316.1.tar.gz
# Optional: Validate the hash
$ echo "75129881e1b80857d235d95a390106470536f5669354cb26af8651861398fa97 actions-runner-osx-arm64-2.316.1.tar.gz" | shasum -a 256 -c
# Extract the installer
$ tar xzf ./actions-runner-osx-arm64-2.316.1.tar.gz Configure # Create the runner and start the configuration experience
$ ./config.sh --url https://github.com/op-tennis/Practice-Backend --token BBADDYBO76DGDFEXYHIJOU3GIDKI2
# Last step, run it!
$ ./run.sh Using your self-hosted runner # Use this YAML in your workflow file for each job
runs-on: self-hosted |
swc/testを使うための設定ファイルなどがないので、テスト失敗する テスト結果 |
参考記事
The text was updated successfully, but these errors were encountered: