Hello World
This commit is contained in:
1
typescript/.gitignore
vendored
Normal file
1
typescript/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
node_modules
|
||||
13
typescript/hello-world/.eslintignore
Normal file
13
typescript/hello-world/.eslintignore
Normal file
@@ -0,0 +1,13 @@
|
||||
!.meta
|
||||
|
||||
# Protected or generated
|
||||
.git
|
||||
.vscode
|
||||
|
||||
# When using npm
|
||||
node_modules/*
|
||||
|
||||
# Configuration files
|
||||
.eslintrc.cjs
|
||||
babel.config.cjs
|
||||
jest.config.cjs
|
||||
38
typescript/hello-world/.eslintrc.cjs
Normal file
38
typescript/hello-world/.eslintrc.cjs
Normal file
@@ -0,0 +1,38 @@
|
||||
module.exports = {
|
||||
root: true,
|
||||
parserOptions: {
|
||||
tsconfigRootDir: __dirname,
|
||||
project: ['./tsconfig.json'],
|
||||
},
|
||||
overrides: [
|
||||
// Student provided files
|
||||
{
|
||||
files: ['*.ts'],
|
||||
excludedFiles: ['.meta/proof.ci.ts', '.meta/exemplar.ts', '*.test.ts'],
|
||||
extends: '@exercism/eslint-config-typescript',
|
||||
},
|
||||
// Exercism given tests
|
||||
{
|
||||
files: ['*.test.ts'],
|
||||
excludedFiles: ['custom.test.ts'],
|
||||
env: {
|
||||
jest: true,
|
||||
},
|
||||
extends: '@exercism/eslint-config-typescript/maintainers',
|
||||
},
|
||||
// Student provided tests
|
||||
{
|
||||
files: ['custom.test.ts'],
|
||||
env: {
|
||||
jest: true,
|
||||
},
|
||||
extends: '@exercism/eslint-config-typescript',
|
||||
},
|
||||
// Exercism provided files
|
||||
{
|
||||
files: ['.meta/proof.ci.ts', '.meta/exemplar.ts', '*.test.ts'],
|
||||
excludedFiles: ['custom.test.ts'],
|
||||
extends: '@exercism/eslint-config-typescript/maintainers',
|
||||
},
|
||||
],
|
||||
}
|
||||
19
typescript/hello-world/.exercism/config.json
Normal file
19
typescript/hello-world/.exercism/config.json
Normal file
@@ -0,0 +1,19 @@
|
||||
{
|
||||
"blurb": "The classical introductory exercise. Just say \"Hello, World!\"",
|
||||
"authors": ["masters3d"],
|
||||
"contributors": [
|
||||
"DFXLuna",
|
||||
"iHiD",
|
||||
"kytrinyx",
|
||||
"lukaszklis",
|
||||
"porkostomus",
|
||||
"SleeplessByte"
|
||||
],
|
||||
"files": {
|
||||
"solution": ["hello-world.ts"],
|
||||
"test": ["hello-world.test.ts"],
|
||||
"example": [".meta/proof.ci.ts"]
|
||||
},
|
||||
"source": "This is an exercise to introduce users to using Exercism",
|
||||
"source_url": "http://en.wikipedia.org/wiki/%22Hello,_world!%22_program"
|
||||
}
|
||||
1
typescript/hello-world/.exercism/metadata.json
Normal file
1
typescript/hello-world/.exercism/metadata.json
Normal file
@@ -0,0 +1 @@
|
||||
{"track":"typescript","exercise":"hello-world","id":"982da4c4be0f4156b076dfb083369865","url":"https://exercism.org/tracks/typescript/exercises/hello-world","handle":"briemens","is_requester":true,"auto_approve":false}
|
||||
44
typescript/hello-world/HELP.md
Normal file
44
typescript/hello-world/HELP.md
Normal file
@@ -0,0 +1,44 @@
|
||||
# Help
|
||||
|
||||
## Running the tests
|
||||
|
||||
Execute the tests with:
|
||||
|
||||
```bash
|
||||
$ yarn test
|
||||
```
|
||||
|
||||
## Skipped tests
|
||||
|
||||
In the test suites all tests but the first have been skipped.
|
||||
|
||||
Once you get a test passing, you can enable the next one by changing `xit` to
|
||||
`it`.
|
||||
|
||||
## Submitting your solution
|
||||
|
||||
You can submit your solution using the `exercism submit hello-world.ts` command.
|
||||
This command will upload your solution to the Exercism website and print the solution page's URL.
|
||||
|
||||
It's possible to submit an incomplete solution which allows you to:
|
||||
|
||||
- See how others have completed the exercise
|
||||
- Request help from a mentor
|
||||
|
||||
## Need to get help?
|
||||
|
||||
If you'd like help solving the exercise, check the following pages:
|
||||
|
||||
- The [TypeScript track's documentation](https://exercism.org/docs/tracks/typescript)
|
||||
- [Exercism's support channel on gitter](https://gitter.im/exercism/support)
|
||||
- The [Frequently Asked Questions](https://exercism.org/docs/using/faqs)
|
||||
|
||||
Should those resources not suffice, you could submit your (incomplete) solution to request mentoring.
|
||||
|
||||
To get help if you're having trouble, you can use one of the following resources:
|
||||
|
||||
- [TypeScript QuickStart](https://www.typescriptlang.org/docs/handbook/release-notes/overview.html)
|
||||
- [ECMAScript 2015 Language Specification](https://www.ecma-international.org/wp-content/uploads/ECMA-262_6th_edition_june_2015.pdf) (pdf)
|
||||
- [Mozilla JavaScript Reference](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference)
|
||||
- [/r/typescript](https://www.reddit.com/r/typescript) is the TypeScript subreddit.
|
||||
- [StackOverflow](https://stackoverflow.com/questions/tagged/typescript) can be used to search for your problem and see if it has been answered already. You can also ask and answer questions.
|
||||
162
typescript/hello-world/README.md
Normal file
162
typescript/hello-world/README.md
Normal file
@@ -0,0 +1,162 @@
|
||||
# Hello World
|
||||
|
||||
Welcome to Hello World on Exercism's TypeScript Track.
|
||||
If you need help running the tests or submitting your code, check out `HELP.md`.
|
||||
|
||||
## Instructions
|
||||
|
||||
The classical introductory exercise. Just say "Hello, World!".
|
||||
|
||||
["Hello, World!"](http://en.wikipedia.org/wiki/%22Hello,_world!%22_program) is
|
||||
the traditional first program for beginning programming in a new language
|
||||
or environment.
|
||||
|
||||
The objectives are simple:
|
||||
|
||||
- Write a function that returns the string "Hello, World!".
|
||||
- Run the test suite and make sure that it succeeds.
|
||||
- Submit your solution and check it at the website.
|
||||
|
||||
If everything goes well, you will be ready to fetch your first real exercise.
|
||||
|
||||
## Setup
|
||||
|
||||
Go through the setup instructions for TypeScript to
|
||||
install the necessary dependencies:
|
||||
|
||||
http://exercism.org/languages/typescript
|
||||
|
||||
## Requirements
|
||||
|
||||
Install assignment dependencies:
|
||||
|
||||
```bash
|
||||
$ yarn install
|
||||
```
|
||||
|
||||
## Making the test suite pass
|
||||
|
||||
Execute the tests with:
|
||||
|
||||
```bash
|
||||
$ yarn test
|
||||
```
|
||||
|
||||
In many test suites all but the first test have been skipped.
|
||||
|
||||
Once you get a test passing, you can unskip the next one by
|
||||
changing `xit` to `it`.
|
||||
|
||||
## Tutorial
|
||||
|
||||
This section is a step-by-step guide to solving this exercise.
|
||||
|
||||
This exercise has two files:
|
||||
|
||||
- hello-world.ts
|
||||
- hello-world.test.ts
|
||||
|
||||
The first file is where you will write your code.
|
||||
The second is where the tests are defined.
|
||||
|
||||
The tests will check whether your code is doing the right thing.
|
||||
You don't need to be able to write a test suite from scratch,
|
||||
but it helps to understand what a test looks like, and what
|
||||
it is doing.
|
||||
|
||||
Open up the test file, hello-world.test.ts.
|
||||
There is a single test inside:
|
||||
|
||||
```typescript
|
||||
it('says hello world', () => {
|
||||
expect(hello()).toEqual('Hello, World!')
|
||||
})
|
||||
```
|
||||
|
||||
Run the test now, with the following command on the command-line:
|
||||
|
||||
```bash
|
||||
$ yarn test
|
||||
```
|
||||
|
||||
The test fails, which makes sense since you've not written any code yet.
|
||||
|
||||
The failure looks like this:
|
||||
|
||||
```
|
||||
× says hello world (5ms)
|
||||
|
||||
● Hello World › says hello world
|
||||
|
||||
expect(received).toEqual(expected) // deep equality
|
||||
|
||||
Expected: "Hello, World!"
|
||||
Received: "Goodbye, Mars!"
|
||||
|
||||
4 |
|
||||
5 | it('says hello world', () => {
|
||||
> 6 | expect(hello()).toEqual('Hello, World!')
|
||||
| ^
|
||||
7 | })
|
||||
8 |
|
||||
9 | })
|
||||
|
||||
at Object.it (hello-world.test.ts:6:32)
|
||||
```
|
||||
|
||||
And these are those code lines with probable defects in the `hello-world.test.ts` file:
|
||||
|
||||
the 6th line:
|
||||
|
||||
```typescript
|
||||
expect(hello()).toEqual('Hello, World!')
|
||||
^
|
||||
```
|
||||
|
||||
Hence the problem is with the `hello()` function call.
|
||||
We can see that the test is expecting `'Hello, World!'` as output, but instead is getting `"Goodbye, Mars!"`.
|
||||
|
||||
So let's check now this function in the `hello-worlds.ts` file:
|
||||
|
||||
```typescript
|
||||
export function hello(): string {
|
||||
return 'Goodbye, Mars!'
|
||||
}
|
||||
```
|
||||
|
||||
Now we see that the function returns the incorrect string, which is the reason for our failure. Let's fix this by changing the returned value:
|
||||
|
||||
```typescript
|
||||
export function hello(): string {
|
||||
return 'Hello, World!'
|
||||
}
|
||||
```
|
||||
|
||||
Run the test again:
|
||||
|
||||
```bash
|
||||
PASS ./hello-world.test.ts
|
||||
Hello World
|
||||
√ says hello world (4ms)
|
||||
```
|
||||
|
||||
And it passes!
|
||||
|
||||
## Source
|
||||
|
||||
### Created by
|
||||
|
||||
- @masters3d
|
||||
|
||||
### Contributed to by
|
||||
|
||||
- @DFXLuna
|
||||
- @iHiD
|
||||
- @kytrinyx
|
||||
- @lukaszklis
|
||||
- @porkostomus
|
||||
- @SleeplessByte
|
||||
|
||||
### Based on
|
||||
|
||||
This is an exercise to introduce users to using Exercism - http://en.wikipedia.org/wiki/%22Hello,_world!%22_program
|
||||
4
typescript/hello-world/babel.config.cjs
Normal file
4
typescript/hello-world/babel.config.cjs
Normal file
@@ -0,0 +1,4 @@
|
||||
module.exports = {
|
||||
presets: ['@exercism/babel-preset-typescript'],
|
||||
plugins: [],
|
||||
}
|
||||
7
typescript/hello-world/hello-world.test.ts
Normal file
7
typescript/hello-world/hello-world.test.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
import { hello } from './hello-world'
|
||||
|
||||
describe('Hello World', () => {
|
||||
it('says hello world', () => {
|
||||
expect(hello()).toEqual('Hello, World!')
|
||||
})
|
||||
})
|
||||
3
typescript/hello-world/hello-world.ts
Normal file
3
typescript/hello-world/hello-world.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
export function hello(): string {
|
||||
return 'Hello, World!'
|
||||
}
|
||||
19
typescript/hello-world/jest.config.cjs
Normal file
19
typescript/hello-world/jest.config.cjs
Normal file
@@ -0,0 +1,19 @@
|
||||
module.exports = {
|
||||
verbose: true,
|
||||
projects: ['<rootDir>'],
|
||||
testMatch: [
|
||||
'**/__tests__/**/*.[jt]s?(x)',
|
||||
'**/test/**/*.[jt]s?(x)',
|
||||
'**/?(*.)+(spec|test).[jt]s?(x)',
|
||||
],
|
||||
testPathIgnorePatterns: [
|
||||
'/(?:production_)?node_modules/',
|
||||
'.d.ts$',
|
||||
'<rootDir>/test/fixtures',
|
||||
'<rootDir>/test/helpers',
|
||||
'__mocks__',
|
||||
],
|
||||
transform: {
|
||||
'^.+\\.[jt]sx?$': 'babel-jest',
|
||||
},
|
||||
}
|
||||
31
typescript/hello-world/package.json
Normal file
31
typescript/hello-world/package.json
Normal file
@@ -0,0 +1,31 @@
|
||||
{
|
||||
"name": "@exercism/typescript-hello-world",
|
||||
"version": "1.0.0",
|
||||
"description": "Exercism exercises in Typescript.",
|
||||
"private": true,
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/exercism/typescript"
|
||||
},
|
||||
"type": "module",
|
||||
"engines": {
|
||||
"node": "^14.13.1 || >=16.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@exercism/babel-preset-typescript": "^0.1.0",
|
||||
"@exercism/eslint-config-typescript": "^0.4.1",
|
||||
"@types/jest": "^27.4.0",
|
||||
"@types/node": "^16.11.24",
|
||||
"babel-jest": "^27.5.1",
|
||||
"core-js": "^3.21.0",
|
||||
"eslint": "^8.9.0",
|
||||
"jest": "^27.5.1",
|
||||
"typescript": "^4.5.4"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "yarn lint:types && jest --no-cache",
|
||||
"lint": "yarn lint:types && yarn lint:ci",
|
||||
"lint:types": "yarn tsc --noEmit -p .",
|
||||
"lint:ci": "eslint . --ext .tsx,.ts"
|
||||
}
|
||||
}
|
||||
28
typescript/hello-world/tsconfig.json
Normal file
28
typescript/hello-world/tsconfig.json
Normal file
@@ -0,0 +1,28 @@
|
||||
{
|
||||
"display": "Configuration for Exercism TypeScript Exercises",
|
||||
"compilerOptions": {
|
||||
// Allows you to use the newest syntax, and have access to console.log
|
||||
// https://www.typescriptlang.org/tsconfig#lib
|
||||
"lib": ["ESNEXT", "dom"],
|
||||
// Make sure typescript is configured to output ESM
|
||||
// https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c#how-can-i-make-my-typescript-project-output-esm
|
||||
"module": "ES2020",
|
||||
// Since this project is using babel, TypeScript may target something very
|
||||
// high, and babel will make sure it runs on your local Node version.
|
||||
// https://babeljs.io/docs/en/
|
||||
"target": "ESNext", // ESLint doesn't support this yet: "es2022",
|
||||
|
||||
"strict": true,
|
||||
"esModuleInterop": true,
|
||||
"skipLibCheck": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
|
||||
// Because we'll be using babel: ensure that Babel can safely transpile
|
||||
// files in the TypeScript project.
|
||||
//
|
||||
// https://babeljs.io/docs/en/babel-plugin-transform-typescript/#caveats
|
||||
"isolatedModules": true
|
||||
},
|
||||
"include": ["*.ts", "*.tsx", ".meta/*.ts", ".meta/*.tsx"],
|
||||
"exclude": ["node_modules"]
|
||||
}
|
||||
4553
typescript/hello-world/yarn.lock
Normal file
4553
typescript/hello-world/yarn.lock
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user