title | theme | highlight-theme | revealOptions | ||
---|---|---|---|---|---|
Tools for Junior Devs (2017 Sep) |
sky |
dracula |
|
- for SLC JS Learners/SLC Free Code Camp
- at September 2017 meeting
- by metasean
The presentation and this repo use reveal-md.
To view the presentation:
- ensure you've run
git clone [email protected]:SLC-JS-Learners/2017-09-tools-for-jrs.git
npm install
- then simply run
reveal-md README.md
- Atom - https://atom.io/
- VS Code - https://code.visualstudio.com/
- Jet Brains - https://www.jetbrains.com/
- Ensure you're a member of the JS Learners group
join at: https://jslearners-slack.herokuapp.com/ - Ensure you're subscribed to:
#current-presentation
OPTIONAL Prereq
- open your
.bash_profile
in your editor of choice, e.g.
atom ~./bash_profile
for Atomcode ~./bash_profile
for VS Code
- add the following, including comment π
## npm use local package bin
## (won't need to install most npm modules with `-g`)
export PATH=${PATH}:node_modules/.bin
- save and close the file
- completely quit and restart all terminal/command line applications, including Atom and VS Code
Live Scratchpad for JavaScript
- head over to https://quokkajs.com/
- click the icon matching your editor
- click the big green "Install in <your editor>" button
- install the downloaded package
- when asked, yes, you do want the pro version options
- via Sequential keyboard shortcut commands or the "Command Palette"
β-K
,J
: Create a new Quokka JavaScript fileβ-K
,Q
: Make current file a Quokka fileβ-K
,O
: Toggle output
β-K
,J
β-S
, save assrc/fizz-buzz.js
- write a call to the non-existent
fizzBuzz
function, followed by//?
fizzBuzz(30) //?
- note the output next to the comment
and in the panel below
(yours will look different -
I've already customized mine) - also explore the following:
//?.
- write an implementation of
fizzBuzz
- note the 2 quokka outputs changing as you write your implementation
Integrated Continuous Testing Tool for JavaScript
- jasmine
- mocha
- qunit
- jest
- ava
- head over to https://wallabyjs.com/
- click the big green "Install" button
- click the big green "Download" button for your editor
- install the downloaded package
- copy the key metasean posted in the
#current-presentation
channel
β-N
(create a new generic file)- add the following:
module.exports = function(wallaby) {
return {
files: ['./src/*.js', '!./src/*.test.js'],
tests: ['./src/*.test.js'],
testFramework: 'tape',
env: {
type: 'node'
},
}
}
β-S
, save it aswallyby.js
- via Sequential keyboard shortcut commands or the "Command Palette"
β-T
,R
: Run testsβ-T
,S
: Stop testsβ-T
,T
: Toggle test panel
Note: In most editors, you can change these keyboard shortcuts (Atom example)
-
β-K
,O
: Toggle Quokka panel -
β-T
,T
: Toggle test panel -
β-T
,R
: Run tests -
Note both the:
- 'tape node module is not found...' prompt in the test panel! (Do not install it π)
- the red Utah~ish shaped Wallaby logo in the lower-right
β-K
,J
(create a new Quokka JS file)β-S
, save it assrc/reverse-str.test.js
- add the require statement for
tape
const test = require('tape')
- Note the first two lines in the Quokka panel!
- Install the "tape" package into the project
(may need to restart the Wallaby tests) - Add the first basic test.
Your reverse-str.test.js file should look something like:
const test = require('tape');
test('reverse a string', t => {
t.plan(1) // EITHER - set async count
t.equals(reverseStr('abcde'), 'edcba')
t.end() // OR - set end
})
- Fix the first error message
β-K
,J
(create a new Quokka JS file)β-S
, save it assrc/reverse-str.js
- write a call to the non-existent
reverseStr
function, followed by//?
reverseStr('stressed') /*?*/
- build out the
reverseStr
function, watching Quokka and Wallaby outputs
- replace
reverseStr('stressed') /*?*/
- with
const reverseStr = s => s .split('') /*?*/ .reverse() .join('') const stressed = reverseStr('stressed') /* ? $.toUpperCase() .split('') */ const desserts = reverseStr('desserts') // ?. stressed module.exports = { reverseStr }
- review results & experiment a little or a lot π
Atom-specific (_sorry VS Coders_π )
/******************************************************************************
_ _ _ _ _ _
| | | | | | | | | | |
__ _ _ _ ___ | | _| | ____ _ | | __ ____ _| | | __ _| |__ _ _
/ _` | | | |/ _ \| |/ | |/ / _` | | | \ \ /\ / / _` | | |/ _` | '_ \| | | |
| (_| | |_| | (_) | <| | (_| | | | \ V V | (_| | | | (_| | |_) | |_| |
\__, |\__,_|\___/|_|\_|_|\_\__,_| | | \_/\_/ \__,_|_|_|\__,_|_.__/ \__, |
| | | | __/ |
|_| |_| |___/
*******************************************************************************/
/*
QUOKKA INLINE
*/
/* other colors for use with quokka inline
- #3f1c1c - reddish
- #3f1c3f - purplish
- #3f3f1c - monkey pukish
*/
.qlc .syntax--comment,
.qlc .syntax--comment + .invisible-character.eol,
.atom-text-editor .line.qlc::after,
atom-text-editor .line.qlc::after,
.atom-text-editor .line.qle::after,
atom-text-editor .line.qle::after {
font-weight: bold;
border-top: thin solid #9d9da5;
border-bottom: thin solid #9d9da5;
}
/* ANY comment on the same line as Quokka inline results */
.qlc .syntax--comment {
padding-left: 0.25ex;
color: hsl(240, 4%, 92%);
}
/* The invisible eol for any line with Quokka inline results */
.qlc .syntax--comment + .invisible-character.eol {
background-color: #9d9da5;
color: #9d9da5;
}
/* actual Quokka inline result */
.atom-text-editor .line.qlc::after,
atom-text-editor .line.qlc::after {
padding-right: 1ex;
background-color: #9d9da5;
color: #0f4c19;
}
.atom-text-editor .line.qle::after,
atom-text-editor .line.qle::after {
background-color: #9d9da5;
color: #631913;
}
/*
QUOKKA & WALLABY PANELS
*/
.quokka-results-view,
.wallaby-tests-view {
font-size: 115%;
}
'.platform-darwin atom-text-editor':
'cmd-k e': 'quokka:make-quokka-from-existing-file'
β-.
- Toggle keybinding-resolver- type the current command you are replacing
- click the command in the keybinding-resolver panel
- copy the commands you want to modify to your customized
keymap.cson
- don't forget to toggle the keybinding-resolver off again
Regular Expressions made easy
β-K
,J
(create a new Quokka JS file)β-S
, save it assrc/reg-exp.js
- grab an example from VerbalExpression's GitHub repo
- make it our own...
// the verbalExpressions module
const VerEx = require('verbal-expressions');
// Create an example of how to test for correctly formed URLs
const tester = VerEx()
.startOfLine()
.then('http')
.maybe('s')
.then('://')
.maybe('www.')
.anythingBut(' ')
.endOfLine();
// Create a function that uses the RegExp object's native test() function
const test = input => (tester.test(input) ? 'valid' : 'invalid')
// Try it on several urls
test('https://www.google.com') //?
test('ww.google.com') //?
// Output the actual expression used: /^(http)(s)?(\:\/\/)(www\.)?([^\ ]*)$/
console.log(tester.toRegExp())
// the verbalExpressions module
const VerEx = require('verbal-expressions')
// Create an example of how to test for correctly formed URLs
const verEx = VerEx()
.startOfLine()
.then('http')
.maybe('s')
.then('://')
.maybe('www.')
.anythingBut(' ')
.endOfLine()
// If invalid, we want an honest-to-goodness Error, so hit MDN
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error#Custom_Error_Types
// Create a new object, that prototypically inherits from the Error constructor
function urlError(message) {
this.name = 'urlError'
this.message = message || 'invalid url'
this.stack = new Error().stack
}
urlError.prototype = Object.create(Error.prototype)
urlError.prototype.constructor = urlError
// Create a function that uses the RegExp object's native test() function
const test = input => {
if (verEx.test(input)) return 'valid'
else throw new urlError()
}
// Try it on several urls
test('https://www.google.com') //?
test('ww.google.com') //?
// Output the actual expression used: /^(http)(s)?(\:\/\/)(www\.)?([^\ ]*)$/
console.log(verEx.toRegExp())