Skip to content

Commit

Permalink
問題を追加
Browse files Browse the repository at this point in the history
  • Loading branch information
takahash committed Nov 28, 2023
1 parent bbcfe33 commit d065bc0
Show file tree
Hide file tree
Showing 15 changed files with 2,273 additions and 0 deletions.
32 changes: 32 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: ci
on:
push:

jobs:
test:
name: Build and Test
timeout-minutes: 15
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v3
with:
fetch-depth: 2
- name: Setup Node.js environment
uses: actions/setup-node@v3
with:
node-version: 18
- run: corepack enable yarn
- id: yarn
run: echo "cache-dir=$(yarn cache dir)" >> $GITHUB_OUTPUT
- uses: actions/cache@v3
name: Setup pnpm cache
with:
path: ${{ steps.yarn.outputs.cache-dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- name: Install dependencies
run: yarn
- name: Test
run: yarn test
130 changes: 130 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
.pnpm-debug.log*

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage
*.lcov

# nyc test coverage
.nyc_output

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# Snowpack dependency directory (https://snowpack.dev/)
web_modules/

# TypeScript cache
*.tsbuildinfo

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional stylelint cache
.stylelintcache

# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variable files
.env
.env.development.local
.env.test.local
.env.production.local
.env.local

# parcel-bundler cache (https://parceljs.org/)
.cache
.parcel-cache

# Next.js build output
.next
out

# Nuxt.js build / generate output
.nuxt
dist

# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and not Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public

# vuepress build output
.vuepress/dist

# vuepress v2.x temp and cache directory
.temp
.cache

# Docusaurus cache and generated files
.docusaurus

# Serverless directories
.serverless/

# FuseBox cache
.fusebox/

# DynamoDB Local files
.dynamodb/

# TernJS port file
.tern-port

# Stores VSCode versions used for testing VSCode extensions
.vscode-test

# yarn v2
.yarn/
.pnp.*

# other
output.png
3 changes: 3 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"recommendations": ["ZixuanChen.vitest-explorer"]
}
1 change: 1 addition & 0 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
nodeLinker: node-modules
Binary file added __test__/answer.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
35 changes: 35 additions & 0 deletions __test__/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { describe, test, expect, vi } from "vitest";
import { readFile, rm, cp } from "fs/promises";

import { main as main1 } from "../script_1";
import { main as main2 } from "../script_2";

describe("外部パッケージの問題1(csv-parse)", () => {
test("問題1の結果が正しい", async () => {
const spy = vi
.spyOn(global.console, "log")
.mockImplementation((args) => args);
await main1();
expect(spy).toHaveLastReturnedWith("国語の平均点: 77.5点");
});
test("成績表の点数を変えても結果が正しい", async () => {
await cp("./__test__/seiseki_other.csv", "./seiseki.csv", { force: true });
const spy = vi
.spyOn(global.console, "log")
.mockImplementation((args) => args);
await main1();
expect(spy).toHaveLastReturnedWith("国語の平均点: 80.7点");
await cp("./__test__/seiseki.csv", "./seiseki.csv", { force: true });
});
});

describe("外部パッケージの問題2(sharp)", () => {
test("問題2の結果が正しい", async () => {
await rm("./output.png").catch(() => {});
await main2();
const answer = await readFile("./__test__/answer.png", "base64");
const result = await readFile("./output.png", "base64");
expect(answer).toEqual(result);
await rm("./output.png");
});
});
5 changes: 5 additions & 0 deletions __test__/seiseki.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
氏名,国語,数学,英語
田中太郎,85,78,92
山田花子,70,65,80
佐藤次郎,95,88,90
鈴木三郎,60,70,75
5 changes: 5 additions & 0 deletions __test__/seiseki_other.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
氏名,国語,数学,英語
岡田健太,80,85,88
伊藤美香,75,72,90
加藤健太郎,90,92,85
中村さち子,78,80,82
Binary file added logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 16 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "ueq-study-nodejs-external-package-answer",
"version": "1.0.0",
"devDependencies": {
"@vitest/coverage-v8": "^0.34.1",
"vitest": "^0.34.1"
},
"type": "module",
"scripts": {
"test": "vitest"
},
"volta": {
"node": "18.17.1",
"yarn": "4.0.2"
}
}
7 changes: 7 additions & 0 deletions script_1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export const main = async () => {
const csvPath = "./seiseki.csv";
const result = 0;
console.log(`国語の平均点: ${result}点`);
};

main();
7 changes: 7 additions & 0 deletions script_2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export const main = async () => {
const imgPath = "./logo.png";
const outputPath = "./output.png";
// 加工したPNGファイルを保存
};

main();
5 changes: 5 additions & 0 deletions seiseki.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
氏名,国語,数学,英語
岡田健太,80,85,88
伊藤美香,75,72,90
加藤健太郎,90,92,85
中村さち子,78,80,82
5 changes: 5 additions & 0 deletions vitest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { defineConfig } from "vitest/config";

export default defineConfig({
test: { dir: "__test__" },
});
Loading

0 comments on commit d065bc0

Please sign in to comment.