commit
3cdf24a234
8 changed files with 3525 additions and 0 deletions
-
8.babelrc.json
-
221.gitignore
-
7.prettierrc
-
29Readme.MD
-
27index.js
-
63index.test.ts
-
43package.json
-
3127yarn.lock
@ -0,0 +1,8 @@ |
|||
{ |
|||
"presets": ["@babel/preset-stage-3", "@babel/preset-env"], |
|||
"plugins": [ |
|||
"@babel/plugin-proposal-optional-chaining", |
|||
"@babel/plugin-transform-destructuring", |
|||
"@babel/plugin-proposal-nullish-coalescing-operator" |
|||
] |
|||
} |
|||
@ -0,0 +1,221 @@ |
|||
|
|||
### Intellij ### |
|||
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider |
|||
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 |
|||
|
|||
.idea |
|||
|
|||
|
|||
# CMake |
|||
cmake-build-*/ |
|||
|
|||
# Mongo Explorer plugin |
|||
.idea/**/mongoSettings.xml |
|||
|
|||
# File-based project format |
|||
*.iws |
|||
|
|||
# IntelliJ |
|||
out/ |
|||
|
|||
# mpeltonen/sbt-idea plugin |
|||
.idea_modules/ |
|||
|
|||
# JIRA plugin |
|||
atlassian-ide-plugin.xml |
|||
|
|||
# Cursive Clojure plugin |
|||
.idea/replstate.xml |
|||
|
|||
# Crashlytics plugin (for Android Studio and IntelliJ) |
|||
com_crashlytics_export_strings.xml |
|||
crashlytics.properties |
|||
crashlytics-build.properties |
|||
fabric.properties |
|||
|
|||
# Editor-based Rest Client |
|||
.idea/httpRequests |
|||
|
|||
# Android studio 3.1+ serialized cache file |
|||
.idea/caches/build_file_checksums.ser |
|||
|
|||
### Intellij Patch ### |
|||
# Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721 |
|||
|
|||
# *.iml |
|||
# modules.xml |
|||
# .idea/misc.xml |
|||
# *.ipr |
|||
|
|||
# Sonarlint plugin |
|||
# https://plugins.jetbrains.com/plugin/7973-sonarlint |
|||
.idea/**/sonarlint/ |
|||
|
|||
# SonarQube Plugin |
|||
# https://plugins.jetbrains.com/plugin/7238-sonarqube-community-plugin |
|||
.idea/**/sonarIssues.xml |
|||
|
|||
# Markdown Navigator plugin |
|||
# https://plugins.jetbrains.com/plugin/7896-markdown-navigator-enhanced |
|||
.idea/**/markdown-navigator.xml |
|||
.idea/**/markdown-navigator-enh.xml |
|||
.idea/**/markdown-navigator/ |
|||
|
|||
# Cache file creation bug |
|||
# See https://youtrack.jetbrains.com/issue/JBR-2257 |
|||
.idea/$CACHE_FILE$ |
|||
|
|||
# CodeStream plugin |
|||
# https://plugins.jetbrains.com/plugin/12206-codestream |
|||
.idea/codestream.xml |
|||
|
|||
### macOS ### |
|||
# General |
|||
.DS_Store |
|||
.AppleDouble |
|||
.LSOverride |
|||
|
|||
# Icon must end with two \r |
|||
Icon |
|||
|
|||
|
|||
# Thumbnails |
|||
._* |
|||
|
|||
# Files that might appear in the root of a volume |
|||
.DocumentRevisions-V100 |
|||
.fseventsd |
|||
.Spotlight-V100 |
|||
.TemporaryItems |
|||
.Trashes |
|||
.VolumeIcon.icns |
|||
.com.apple.timemachine.donotpresent |
|||
|
|||
# Directories potentially created on remote AFP share |
|||
.AppleDB |
|||
.AppleDesktop |
|||
Network Trash Folder |
|||
Temporary Items |
|||
.apdisk |
|||
|
|||
### Node ### |
|||
# Logs |
|||
logs |
|||
*.log |
|||
npm-debug.log* |
|||
yarn-debug.log* |
|||
yarn-error.log* |
|||
lerna-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/ |
|||
|
|||
# TypeScript v1 declaration files |
|||
typings/ |
|||
|
|||
# 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 variables file |
|||
.env |
|||
.env.test |
|||
.env*.local |
|||
|
|||
# parcel-bundler cache (https://parceljs.org/) |
|||
.cache |
|||
.parcel-cache |
|||
|
|||
# Next.js build output |
|||
.next |
|||
|
|||
# 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 |
|||
|
|||
# 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 |
|||
|
|||
### vscode ### |
|||
.vscode/* |
|||
!.vscode/settings.json |
|||
!.vscode/tasks.json |
|||
!.vscode/launch.json |
|||
!.vscode/extensions.json |
|||
*.code-workspace |
|||
@ -0,0 +1,7 @@ |
|||
{ |
|||
"semi": true, |
|||
"singleQuote": true, |
|||
"printWidth": 80, |
|||
"quoteProps": "consistent", |
|||
"trailingComma": "all" |
|||
} |
|||
@ -0,0 +1,29 @@ |
|||
# Ecmascript tp |
|||
|
|||
This practice is a fastify api agregator. |
|||
|
|||
Please reference to the lab for what to do. |
|||
|
|||
## Install |
|||
|
|||
```shell |
|||
$ yarn install |
|||
# OR |
|||
$ npm install |
|||
``` |
|||
|
|||
## Start the server |
|||
|
|||
```shell |
|||
$ yarn start |
|||
# OR |
|||
$ npm run start |
|||
``` |
|||
|
|||
## Test the server |
|||
|
|||
```shell |
|||
$ yarn test |
|||
# OR |
|||
$ npm run test |
|||
``` |
|||
@ -0,0 +1,27 @@ |
|||
import fastify from 'fastify'; |
|||
// see axios doc on how to use it
|
|||
import axios from 'axios'; |
|||
|
|||
const app = fastify({ logger: true }); |
|||
|
|||
app.post('/', async (req, res) => { |
|||
return { |
|||
message: `Welcome to Node Babel with ${ |
|||
req.body?.testValue ?? 'no testValue' |
|||
}`,
|
|||
}; |
|||
}); |
|||
|
|||
// Only used for dev server, do not remove
|
|||
app.head('/', () => ({ ping: 'pong' })); |
|||
|
|||
// Run the server!
|
|||
const start = async () => { |
|||
try { |
|||
await app.listen(5000); |
|||
} catch (err) { |
|||
app.log.error(err); |
|||
process.exit(1); |
|||
} |
|||
}; |
|||
start(); |
|||
@ -0,0 +1,63 @@ |
|||
import { it, describe, expect, test } from 'vitest'; |
|||
import axios from 'axios'; |
|||
import { string, z } from 'zod'; |
|||
import util from 'node:util'; |
|||
|
|||
const schema = z.object({ |
|||
foxPicture: z.string().url(), |
|||
catFacts: z.string().array().length(3), |
|||
holidays: z |
|||
.object({ |
|||
date: z.string(), |
|||
localName: string(), |
|||
name: z.string(), |
|||
countryCode: z.string(), |
|||
fixed: z.boolean(), |
|||
global: z.boolean(), |
|||
contries: z.any(), |
|||
launchYear: z.number().nullable(), |
|||
types: z.string().array(), |
|||
}) |
|||
.array(), |
|||
}); |
|||
|
|||
const fullShow = (obj) => |
|||
util.inspect(obj, { showHidden: false, depth: null, colors: true }); |
|||
|
|||
test('Api result should be the correct shape', async () => { |
|||
const { data } = await axios.post('http://localhost:5000', { |
|||
countryCode: 'FR', |
|||
}); |
|||
console.log(fullShow(data)); |
|||
const parsed = schema.safeParse(data); |
|||
if (parsed.success !== true) { |
|||
console.error(fullShow(parsed.error.format())); |
|||
} |
|||
expect(parsed.success).toBeTruthy(); |
|||
}); |
|||
|
|||
describe('Holidays', () => { |
|||
it('should be of this year', async () => { |
|||
const { data } = await axios.post('http://localhost:5000', { |
|||
countryCode: 'FR', |
|||
}); |
|||
const parsed = schema.parse(data); |
|||
|
|||
parsed.holidays.forEach((item) => expect(item.date).toContain('2022')); |
|||
}); |
|||
|
|||
it.each(['FR', 'BE', 'GB'])( |
|||
'use the country code in the api response', |
|||
async (contryCode) => { |
|||
const { data } = await axios.post('http://localhost:5000', { |
|||
countryCode: 'FR', |
|||
}); |
|||
|
|||
const parsed = schema.parse(data); |
|||
|
|||
parsed.holidays.forEach((item) => |
|||
expect(item.countryCode === contryCode), |
|||
); |
|||
}, |
|||
); |
|||
}); |
|||
@ -0,0 +1,43 @@ |
|||
{ |
|||
"name": "2020-2021-angular-ecma-tp", |
|||
"version": "1.0.0", |
|||
"main": "index.js", |
|||
"license": "MIT", |
|||
"dependencies": { |
|||
"@babel/core": "^7.12.16", |
|||
"@babel/node": "^7.12.16", |
|||
"@babel/plugin-proposal-nullish-coalescing-operator": "^7.12.13", |
|||
"@babel/plugin-proposal-optional-chaining": "^7.12.16", |
|||
"@babel/plugin-transform-destructuring": "^7.12.13", |
|||
"@babel/preset-env": "^7.12.16", |
|||
"@babel/preset-stage-3": "^7.8.3", |
|||
"axios": "^0.21.1", |
|||
"fastify": "^3.12.0", |
|||
"nodemon": "^2.0.7", |
|||
"zod": "^3.11.6" |
|||
}, |
|||
"devDependencies": { |
|||
"husky": "5.0.9", |
|||
"prettier": "2.2.1", |
|||
"pretty-quick": "3.1.0", |
|||
"start-server-and-test": "^1.14.0", |
|||
"vitest": "^0.3.4" |
|||
}, |
|||
"scripts": { |
|||
"start": "nodemon exec babel-node index.js", |
|||
"test": "start-server-and-test test:server http://localhost:5000 test:run", |
|||
"test:server": "babel-node index.js", |
|||
"test:run": "vitest run", |
|||
"format:write": "prettier --write \"**/*.{js,vue,json,ts,tsx,md,yml,html}\"", |
|||
"format:check": "prettier --list-different \"**/*.{js,vue,json,ts,tsx,md,yml,html}\"" |
|||
}, |
|||
"engines": { |
|||
"node": ">=14" |
|||
}, |
|||
"type": "module", |
|||
"husky": { |
|||
"hooks": { |
|||
"pre-commit": "pretty-quick --staged" |
|||
} |
|||
} |
|||
} |
|||
3127
yarn.lock
File diff suppressed because it is too large
View File
File diff suppressed because it is too large
View File
Write
Preview
Loading…
Cancel
Save
Reference in new issue