Skip to content

Several basic examples and experiments with JavaScript

License

Notifications You must be signed in to change notification settings

francescozanoni/javascript-hodgepodge

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

83 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

My JavaScript hodgepodge

Several basic examples and experiments with JavaScript.

Examples

  • src/fetch-ibans: fetch many sample IBANs from several websites, in parallel with node-fetch package and Promises
  • src/headless-browser: use a headless browser (e.g. Chrome) to surf the web
  • src/node-events: NodeJS custom event management
  • src/openapi-path-detector: find OpenAPI path definition of a web request
  • src/react: React JS usage with event-driven component communication
  • src/streams: examples with Node's streams
  • src/browser-events.html: web browser custom event management
  • src/error-within-async.js: examples of error raised within async function
  • src/property-existence-check.js: how to check for existence of an object property
  • src/read-text-file-lines.js: read specific lines from text file with OS tools
  • src/tree.html: tree rendering example with Treant.js package
  • src/utils.html: few utility functions
  • src/validation-with-json-schema.js: data validation via JSON schema with Ajv package
  • .eslintrc.json: configuration for ESLint package

Test examples

  • tests/error-within-async.test.js: ensure unexpected errors raised within asynchronous code do not jeopardize tests performed by Jest framework
  • tests/fastify.test.js: test Fastify-based web application
  • tests/fs-mock.test.js: mock external module functions with Jest framework
  • tests/http-server-mock.test.js: test client functionalities by mocking an HTTP server with nock package
  • tests/node-fetch.test.js: HTTP request/response test with node-fetch package
  • tests/openapi-validator.test.js: validate API response against OpenAPI schema with jest-openapi package

Experiments

  • src/aiken-validator: validate questions in Aiken format (used by Moodle LMS)

Installation

docker run -v ${PWD}:/code -w /code --rm node:alpine yarn install

Test

docker run -v ${PWD}:/code -w /code --rm node:alpine yarn test

Code linting

docker run -v ${PWD}:/code -w /code --rm node:alpine yarn lint

Notes

  • test files are suffixed with .test.js, in order to comply with Jest default: this makes no further configuration required
  • in order to avoid warning Unresolved function/method/variable within IDE, @types/jest package has been added, as suggested here
  • (this could seem advertising, I know) a LOT of examples can be found on book JavaScript: The Definitive Guide (7th ed.), by David Flanagan