-
Notifications
You must be signed in to change notification settings - Fork 13
Aliza lab #5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
aliza89p
wants to merge
5
commits into
sea-401d5-javascript:master
Choose a base branch
from
aliza89p:aliza-lab
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Aliza lab #5
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| const gulp = require('gulp'); | ||
| const eslint = require('gulp-eslint'); | ||
| const mocha = require ('gulp-mocha'); | ||
|
|
||
| gulp.task('default', ['lint', 'mocha'], () => { | ||
| console.log('default for lint and mocha'); | ||
| }); | ||
|
|
||
|
|
||
| gulp.task('lint', () => { | ||
| gulp.src('/*.js') | ||
| .pipe(eslint({})) | ||
| .pipe(eslint.format()) | ||
| }); | ||
|
|
||
| gulp.task('mocha', () => { | ||
| gulp.src('test/test.js') | ||
| .pipe(mocha()); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| { | ||
| "name": "aliza", | ||
| "version": "1.0.0", | ||
| "description": "", | ||
| "main": "promise.js", | ||
| "directories": { | ||
| "test": "test" | ||
| }, | ||
| "scripts": { | ||
| "test": "echo \"Error: no test specified\" && exit 1", | ||
| "start": "node server.js" | ||
| }, | ||
| "keywords": [], | ||
| "author": "", | ||
| "license": "ISC", | ||
| "devDependencies": { | ||
| "chai": "^3.5.0", | ||
| "chai-http": "^2.0.1", | ||
| "gulp": "^3.9.1", | ||
| "gulp-eslint": "^2.0.0", | ||
| "gulp-mocha": "^2.2.0", | ||
| "mocha": "^2.4.5" | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| 'use strict'; | ||
| const fs = require('fs'); | ||
| const http = require('http'); | ||
| const stream = require('stream'); | ||
|
|
||
| http.createServer((req, res) => { | ||
| if (req.url === '/notes' && req.method === 'GET'){ | ||
| fs.readdir(__dirname + '/notes/', (err, files) => { | ||
| res.write(files.toString() + '\n') | ||
| res.end('files listed \n'); | ||
| }); | ||
| } else if (req.url === '/notes' && req.method === 'POST'){ | ||
| let bufStr = ''; | ||
| req.on('data', (data) => { | ||
| bufStr += data.toString(); | ||
| }); | ||
| req.on('end', () => { | ||
| var nextFile = fs.readdirSync(__dirname + '/notes/').length + 1; | ||
| let file = fs.createWriteStream(__dirname + '/notes/' + nextFile + '.json'); | ||
| let bufferStream = new stream.PassThrough(); | ||
| let inBuf = new Buffer(bufStr); | ||
| bufferStream.end(inBuf); | ||
| bufferStream.pipe(file); | ||
| res.statusCode = 200; | ||
| res.end('data written to file \n'); | ||
| }); | ||
| } else { | ||
| res.status = 404; | ||
| res.end('File not found\n'); | ||
| } | ||
| }).listen(3000, () => { | ||
| console.log('server up at 3000 \n'); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| const fs = require('fs'); | ||
| const chai = require('chai'); | ||
| const chaiHTTP = require('chai-http'); | ||
| const expect = chai.expect; | ||
| chai.use(chaiHTTP); | ||
| const request = chai.request; | ||
| var fileArr = []; | ||
| var newFileArr = []; | ||
|
|
||
| require('../server'); | ||
|
|
||
| describe('HTTP tests', () => { | ||
| before('reading files in notes directory', () => { | ||
| fileArr = fs.readdirSync(__dirname + '/../notes'); | ||
| }); | ||
| it('should read file names on get request', (done) => { | ||
| request('localhost:3000') | ||
| .get('/notes') | ||
| .end((err, res) => { | ||
| expect(err).to.eql(null); | ||
| expect(res).to.have.status(200); | ||
| expect(res.text).to.eql(fs.readdirSync(__dirname + '/../notes').toString() + '\n' + 'files listed \n'); | ||
| done(); | ||
| }); | ||
| }); | ||
| it('should post to new file on post request', (done) => { | ||
| request('localhost:3000') | ||
| .post('/notes') | ||
| .send('{"blah": "blah"}') | ||
| .end((err, res) => { | ||
| newFileArr = fs.readdirSync(__dirname + '/../notes'); | ||
| expect(err).to.eql(null); | ||
| expect(newFileArr).to.not.eql(fileArr); | ||
| done(); | ||
| }) | ||
| }) | ||
| }); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good - if you have some time we could talk about how to refactor to using returns instead of if/then/else. I