Skip to content

Commit 762ba80

Browse files
committed
Initial commit
0 parents  commit 762ba80

10 files changed

+315
-0
lines changed

Diff for: .editorconfig

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
root = true
2+
3+
[*]
4+
end_of_line = lf
5+
indent_style = space
6+
insert_final_newline = true
7+
8+
[*{.java,.py}]
9+
indent_size = 4
10+
11+
[*.{js,json,rb}]
12+
charset = utf-8
13+
indent_size = 2

Diff for: .gitignore

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Created by https://www.gitignore.io/api/node
2+
3+
### Node ###
4+
# Logs
5+
logs
6+
*.log
7+
npm-debug.log*
8+
9+
# Runtime data
10+
pids
11+
*.pid
12+
*.seed
13+
14+
# Directory for instrumented libs generated by jscoverage/JSCover
15+
lib-cov
16+
17+
# Coverage directory used by tools like istanbul
18+
coverage
19+
20+
# nyc test coverage
21+
.nyc_output
22+
23+
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
24+
.grunt
25+
26+
# node-waf configuration
27+
.lock-wscript
28+
29+
# Compiled binary addons (http://nodejs.org/api/addons.html)
30+
build/Release
31+
32+
# Dependency directories
33+
node_modules
34+
jspm_packages
35+
36+
# Optional npm cache directory
37+
.npm
38+
39+
# Optional REPL history
40+
.node_repl_history
41+
42+
# Learn-specific .results.json
43+
.results.json

Diff for: .learn

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
tags:
2+
- javascript
3+
languages:
4+
- javascript
5+
resources:
6+
- 1

Diff for: CONTRIBUTING.md

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Contributing to Learn.co Curriculum
2+
3+
We're really excited that you're about to contribute to the [open curriculum](https://learn.co/content-license) on [Learn.co](https://learn.co). If this is your first time contributing, please continue reading to learn how to make the most meaningful and useful impact possible.
4+
5+
## Raising an Issue to Encourage a Contribution
6+
7+
If you notice a problem with the curriculum that you believe needs improvement
8+
but you're unable to make the change yourself, you should raise a Github issue
9+
containing a clear description of the problem. Include relevant snippets of
10+
the content and/or screenshots if applicable. Curriculum owners regularly review
11+
issue lists and your issue will be prioritized and addressed as appropriate.
12+
13+
## Submitting a Pull Request to Suggest an Improvement
14+
15+
If you see an opportunity for improvement and can make the change yourself go
16+
ahead and use a typical git workflow to make it happen:
17+
18+
* Fork this curriculum repository
19+
* Make the change on your fork, with descriptive commits in the standard format
20+
* Open a Pull Request against this repo
21+
22+
A curriculum owner will review your change and approve or comment on it in due
23+
course.
24+
25+
# Why Contribute?
26+
27+
Curriculum on Learn is publicly and freely available under Learn's
28+
[Educational Content License](https://learn.co/content-license). By
29+
embracing an open-source contribution model, our goal is for the curriculum
30+
on Learn to become, in time, the best educational content the world has
31+
ever seen.
32+
33+
We need help from the community of Learners to maintain and improve the
34+
educational content. Everything from fixing typos, to correcting
35+
out-dated information, to improving exposition, to adding better examples,
36+
to fixing tests—all contributions to making the curriculum more effective are
37+
welcome.

Diff for: LICENSE.md

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Learn.co Educational Content License
2+
3+
Copyright (c) 2016 Flatiron School, Inc
4+
5+
The Flatiron School, Inc. owns this Educational Content. However, the Flatiron School supports the development and availability of educational materials in the public domain. Therefore, the Flatiron School grants Users of the Flatiron Educational Content set forth in this repository certain rights to reuse, build upon and share such Educational Content subject to the terms of the Educational Content License set forth [here](http://learn.co/content-license) (http://learn.co/content-license). You must read carefully the terms and conditions contained in the Educational Content License as such terms govern access to and use of the Educational Content.
6+
7+
Flatiron School is willing to allow you access to and use of the Educational Content only on the condition that you accept all of the terms and conditions contained in the Educational Content License set forth [here](http://learn.co/content-license) (http://learn.co/content-license). By accessing and/or using the Educational Content, you are agreeing to all of the terms and conditions contained in the Educational Content License. If you do not agree to any or all of the terms of the Educational Content License, you are prohibited from accessing, reviewing or using in any way the Educational Content.

Diff for: README.md

+123
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
JavaScript Logging Lab
2+
---
3+
4+
## Objectives
5+
6+
1. Practice using `console.log()`
7+
2. Practice using `console.error()`
8+
3. Practice using `console.warn()`
9+
10+
11+
## Introduction
12+
13+
Welcome to your first JavaScript lab! You'll notice a few new things in this lesson that we haven't encountered before. Don't worry, we'll walk you through them.
14+
15+
### Structure
16+
17+
The structure of this lab — where its files and folders are located — looks roughly like the following:
18+
19+
``` shell
20+
├── CONTRIBUTING.md
21+
├── LICENSE.md
22+
├── README.md
23+
├── index.js
24+
├── node_modules/
25+
├── package.json
26+
└── test
27+
└── index-test.js
28+
```
29+
30+
All labs will more or less have the same structure. (And READMEs, for that matter, will still have CONTRIBUTING.md, LICENSE.md, and README.md files.)
31+
32+
`index.js` might be called something else (something more descriptive) in other labs, and so `test/index-test.js` would be renamed accordingly. But `index.js` is also descriptive in its own right, defining something of an entry point for finding one's way around the app. This is often the file where you will write your code. (Later on, we'll introduce `index.html` and `index.css` — you'll have to update or refer to these files sometimes, too!)
33+
34+
### Code-along
35+
36+
For now, open up `index.js` in your text editor. You should see, well, nothing. We'll fix that soon.
37+
38+
Now upon up `test/index-test.js`. Hey, there's something! What's all of this stuff doing?
39+
40+
At the very top of the file, you'll see
41+
42+
``` javascript
43+
const expect = require('expect')
44+
const fs = require('fs')
45+
const jsdom = require('mocha-jsdom')
46+
const path = require('path')
47+
```
48+
49+
This might be a bit bewildering, but all we're doing is referencing different _libraries_ that help us run your tests. A library is code that someone else (usually multiple someone elses) wrote for our use. Note that `require` won't work out of the box in the browser. We're actually running our tests in a different _environment_. (Remember the sandbox analogy from earlier? It's just like that.)
50+
51+
A little farther down the page, you'll see
52+
53+
``` javascript
54+
describe('index', () => {
55+
// there's stuff in here, too
56+
})
57+
```
58+
59+
`describe` is a function provided by our test runner (in this case, we're using [Mocha](https://mochajs.org/)) — it's basically a container for our tests.
60+
61+
Then we have a few chunks like
62+
63+
``` javascript
64+
it('calls console.error()`, () => {
65+
// this is where the tests are!
66+
})
67+
```
68+
69+
Each of these chunks describes a behavior that we expect the main program to implement. As you can see, they describe that behavior pretty carefully — in this example, we know that our main file should call `console.error()` — pretty simple, right?
70+
71+
Don't worry too much yet about what's happening inside these chunks. Sometimes we'll need to do some pretty fancy footwork to test some pretty basic things; other times, and as time goes on, you'll be able to read and understand basically what our tests are expecting.
72+
73+
And that'll be great! These aren't like tests that we all took in school: they're testing behavior, not information. Tests are meant to be as transparent as possible about what they're doing, and as you grow as a programmer, it's important to understand more and more what the aims of tests are.
74+
75+
In some of our tests, you'll see lines like the following:
76+
77+
``` javascript
78+
jsdom({
79+
src: fs.readFileSync(path.resolve(__dirname, '..', 'index.js'), 'utf-8')
80+
})
81+
```
82+
83+
This line reads `index.js` (remember how we said we'd modify that?) and adds its code to the _execution environment_. The "execution environment" is simply where our code runs.
84+
85+
## Running the Tests
86+
87+
To run the tests, simply type `learn test` in the Learn IDE. You should see something like
88+
89+
![failures](https://curriculum-content.s3.amazonaws.com/skills-based-js/console_lab_test_failures.png)
90+
91+
For the moment, all of the tests fail. Let's figure out how to get one of them passing! (The rest will be up to you.)
92+
93+
Let's take the first one. The test description says, "index calls console.error()". So it sounds like, pretty straight-forwardly, like we should call `console.error()`.
94+
95+
In `index.js`, add a call to `console.error()` — you can call it with anything you like (as long as the syntax is valid). We're going to go with
96+
97+
``` javascript
98+
console.error("HALP!")
99+
```
100+
101+
Because it seems sufficiently dire.
102+
103+
Anyway, let's run the tests again. In the Learn IDE's terminal, run
104+
105+
``` javascript
106+
learn test
107+
```
108+
109+
We should now see:
110+
111+
![one passing](https://curriculum-content.s3.amazonaws.com/skills-based-js/console_lab_test_one_passing.png)
112+
113+
Nice! We got the first one to pass!
114+
115+
## Your turn
116+
117+
Now it's your turn — can you follow a flow similar to the one we followed together above to get the remaining to tests to pass?
118+
119+
When all of your tests pass, be sure to run `learn submit` to move on to the next lesson.
120+
121+
## Resources
122+
123+
- [npm](https://npmjs.org)

Diff for: index.js

Whitespace-only changes.

Diff for: index.solution.js

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
console.error("help!")
2+
3+
console.log('hello!')
4+
5+
console.warn('warning!')

Diff for: package.json

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
{
2+
"name": "java-script-logging-lab",
3+
"version": "0.1.0",
4+
"description": "Practice writing a log statement",
5+
"engines": {
6+
"node": "6.x",
7+
"npm": "3.x"
8+
},
9+
"main": "index.js",
10+
"scripts": {
11+
"test": "mocha -R mocha-multi --reporter-options nyan=-,json=.results.json"
12+
},
13+
"repository": {
14+
"type": "git",
15+
"url": "git+ssh://[email protected]/learn-co-curriculum/java-script-logging-lab.git"
16+
},
17+
"keywords": [
18+
"javascript",
19+
"flatiron",
20+
"learn"
21+
],
22+
"author": "pletcher",
23+
"license": "SEE LICENSE IN LICENSE.md",
24+
"bugs": {
25+
"url": "https://github.com/learn-co-curriculum/java-script-logging-lab/issues"
26+
},
27+
"homepage": "https://github.com/learn-co-curriculum/java-script-logging-lab#readme",
28+
"devDependencies": {
29+
"expect": "^1.20.1",
30+
"jsdom": "^9.2.1",
31+
"mocha": "^2.5.3",
32+
"mocha-jsdom": "^1.1.0",
33+
"mocha-multi": "^0.9.0"
34+
}
35+
}

Diff for: test/index-test.js

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
const expect = require('expect')
2+
const fs = require('fs')
3+
const jsdom = require('jsdom')
4+
const path = require('path')
5+
6+
7+
describe('index', () => {
8+
const html = '<div></div>'
9+
const src = path.resolve(__dirname, '..', 'index.js')
10+
11+
it('calls console.error()', done => {
12+
const spy = expect.spyOn(console, 'error').andCallThrough()
13+
14+
jsdom.env(html, [src], {
15+
virtualConsole: jsdom.createVirtualConsole().sendTo(console)
16+
}, (err, window) => {
17+
expect(spy).toHaveBeenCalled()
18+
console.error.restore()
19+
done()
20+
})
21+
})
22+
23+
it('calls console.log()', done => {
24+
const spy = expect.spyOn(console, 'log').andCallThrough()
25+
26+
jsdom.env(html, [src], {
27+
virtualConsole: jsdom.createVirtualConsole().sendTo(console)
28+
}, (err, window) => {
29+
expect(spy).toHaveBeenCalled()
30+
console.log.restore()
31+
done()
32+
})
33+
})
34+
35+
it('calls console.warn()', done => {
36+
const spy = expect.spyOn(console, 'warn').andCallThrough()
37+
38+
jsdom.env(html, [src], {
39+
virtualConsole: jsdom.createVirtualConsole().sendTo(console)
40+
}, (err, window) => {
41+
expect(spy).toHaveBeenCalled()
42+
console.warn.restore()
43+
done()
44+
})
45+
})
46+
})

0 commit comments

Comments
 (0)