Browse Source

Hello world

master
Julio Biason 3 years ago
parent
commit
9a312533e9
  1. 3
      .gitignore
  2. 4
      README.md
  3. 12
      typescript/hello-world/.eslintignore
  4. 23
      typescript/hello-world/.eslintrc
  5. 19
      typescript/hello-world/.exercism/config.json
  6. 1
      typescript/hello-world/.exercism/metadata.json
  7. 44
      typescript/hello-world/HELP.md
  8. 162
      typescript/hello-world/README.md
  9. 20
      typescript/hello-world/babel.config.js
  10. 7
      typescript/hello-world/hello-world.js
  11. 8
      typescript/hello-world/hello-world.test.js
  12. 7
      typescript/hello-world/hello-world.test.ts
  13. 3
      typescript/hello-world/hello-world.ts
  14. 19
      typescript/hello-world/jest.config.js
  15. 33
      typescript/hello-world/package.json
  16. 19
      typescript/hello-world/tsconfig.json
  17. 5164
      typescript/hello-world/yarn.lock

3
.gitignore vendored

@ -19,3 +19,6 @@ _build
# Python
**/__pycache__/**
# TypeScript/JavaScript
**/node_modules/**

4
README.md

@ -20,6 +20,6 @@ THE SOURCE IS PROVIDE AS-IS WITHOUT WARRANTY OF ANY KIND. USE AT YOUR RISK. KEEP
| PHP | 𝍩 |
| Python | 𝍩 |
| Racket | 𝍩 |
| Rust | |
| Swift | |
| Rust | 𝍩 |
| Swift | Out, Exercism requires Xcode |
| Typescript | |

12
typescript/hello-world/.eslintignore

@ -0,0 +1,12 @@
!.meta
# Protected or generated
.git
.vscode
# When using npm
node_modules/*
# Configuration files
babel.config.js
jest.config.js

23
typescript/hello-world/.eslintrc

@ -0,0 +1,23 @@
{
"root": true,
"parser": "@typescript-eslint/parser",
"parserOptions": {
"project": "./tsconfig.json",
"ecmaFeatures": {
"jsx": true
},
"ecmaVersion": 2020,
"sourceType": "module"
},
"extends": "@exercism/eslint-config-typescript",
"env": {
"jest": true
},
"overrides": [
{
"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

@ -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

@ -0,0 +1 @@
{"track":"typescript","exercise":"hello-world","id":"3354519c254c4071a6b3bd8a5b3c7773","url":"https://exercism.org/tracks/typescript/exercises/hello-world","handle":"JBiason","is_requester":true,"auto_approve":false}

44
typescript/hello-world/HELP.md

@ -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

@ -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.io/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: "What's up doc 👋🏽?"
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 `"What's up doc 👋🏽?"`.
So let's check now this function in the `hello-worlds.ts` file:
```typescript
export function hello(): string {
return "What's up doc 👋🏽?"
}
```
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

20
typescript/hello-world/babel.config.js

@ -0,0 +1,20 @@
module.exports = {
presets: [
[
'@babel/preset-env',
{
targets: {
node: 'current',
},
useBuiltIns: 'entry',
corejs: '3.17',
},
],
'@babel/preset-typescript',
],
plugins: [
'@babel/proposal-class-properties',
'@babel/proposal-object-rest-spread',
'@babel/plugin-syntax-bigint',
],
}

7
typescript/hello-world/hello-world.js

@ -0,0 +1,7 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.hello = void 0;
function hello() {
return 'Hello, World!';
}
exports.hello = hello;

8
typescript/hello-world/hello-world.test.js

@ -0,0 +1,8 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const hello_world_1 = require("./hello-world");
describe('Hello World', () => {
it('says hello world', () => {
expect(hello_world_1.hello()).toEqual('Hello, World!');
});
});

7
typescript/hello-world/hello-world.test.ts

@ -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

@ -0,0 +1,3 @@
export function hello(): string {
return 'Goodbye, Mars!'
}

19
typescript/hello-world/jest.config.js

@ -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',
},
}

33
typescript/hello-world/package.json

@ -0,0 +1,33 @@
{
"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"
},
"devDependencies": {
"@babel/core": "^7.15.5",
"@babel/plugin-proposal-class-properties": "^7.14.5",
"@babel/plugin-proposal-object-rest-spread": "^7.14.7",
"@babel/plugin-syntax-bigint": "^7.8.3",
"@babel/preset-env": "^7.15.4",
"@babel/preset-typescript": "^7.15.0",
"@types/jest": "^26.0.24",
"@types/node": "^14.17.14",
"@exercism/eslint-config-typescript": "^0.3.0",
"babel-jest": "^26.6.3",
"core-js": "^3.17.2",
"eslint": "^7.32.0",
"eslint-plugin-import": "^2.24.2",
"jest": "^26.6.3",
"typescript": "^4.4.2"
},
"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"
}
}

19
typescript/hello-world/tsconfig.json

@ -0,0 +1,19 @@
{
"display": "Configuration for Node LTS",
"compilerOptions": {
"lib": ["es2020"],
"module": "commonjs",
"target": "es2020",
"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
"isolatedModules": true
},
"include": ["*", ".meta/*"],
"exclude": ["node_modules"]
}

5164
typescript/hello-world/yarn.lock

File diff suppressed because it is too large Load Diff
Loading…
Cancel
Save