Coder Social home page Coder Social logo

js-assessment's Introduction

Build Status

A test-driven JS assessment

This repo includes a set of tests that can be used to assess the skills of a candidate for a JavaScript position, or to evaluate and improve one's own skills.

I want to work on the tests; what do I do?

To use the tests, you will need to install Node. Note that on Windows, there are some reports that you will need to restart after installing Node - see #12.

You can clone or download this repo. Once you have done so, from the root directory of the repo, run:

npm install
npm start

You can then view the tests in your browser at http://localhost:4444.

When you visit that page, all of the tests should be failing; your job is to get the tests to pass. To do this, you'll need to refer to the tests in the files in the tests/app directory, and edit the files in the app/ directory. Once you update a test, you can reload the test page in the browser to see whether it worked.

You can also run (most of) the tests on the command line:

npm test

The command line runner is a work in progress; contributions welcome :)

Available dependencies

The repo includes jQuery, Backbone, and Underscore. You can use these libraries when writing your solutions!

I want to contribute tests; what do I do?

Submit a pull request! The tests are currently loosely organized by topic, so you should do your best to add tests to the appropriate file in tests/app, or create a new file there if you don't see an appropriate one. If you do create a new file, make sure to add it to tests/runner.js, and to add a stub for the solution to the corresponding file in app/. Finally, it would be great if you could update the answers as well.

If you're not sure how or where to add a test, please open an issue.

Data-driven tests

If your tests need data that can be fetched via XHR, stick a .json file in the data directory; you can access it at /data/<filename>.json.

I want to see the answers!

First, bear in mind that looking up the answers is going to teach you a whole lot less than you'll learn by working on the tests, even if you occasionally get stuck. I'd recommend only looking at the answers once you have the tests passing, to see if there's another way you could have approached the problem. When you're ready to look at the answers, you can find them here; I'll do my best to keep them up to date.

I hate <some technology you've chosen>

This repo uses Mocha and Chai for the tests themselves. It uses the BDD style for authoring tests. If this doesn't suit you, please fork away, or, better, submit a pull request that lets this be more flexible than it currently is.

Todos

There are a number of things that would make this project better; check out the issues for details, pull requests welcome!

License

Copyright © 2012-2016 Rebecca Murphey with many thanks to several contributors.

Creative Commons License

This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.

js-assessment's People

Contributors

adrianheine avatar ainthek avatar ashleygwilliams avatar beeeswax avatar bmaland avatar craveytrain avatar davidrunger2 avatar dsbonev avatar gitter-badger avatar jamesplease avatar joholo avatar jtmalinowski avatar jugglinmike avatar kadamwhite avatar kanenathan213 avatar kmiyashiro avatar loickreitmann avatar pete-the-pete avatar plemarquand avatar raybaxter avatar rmurphey avatar rockbot avatar sgtpooki avatar techmaverick avatar thibaudcolas avatar timhirsh avatar tkissing avatar tomfuertes avatar unthunk avatar uxfed avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

js-assessment's Issues

bug in the async tests?

I have the code following code in app/async.js

async : function(value) {

        return $.Deferred(function(deferred){
            //demonstrate that this is async
            setTimeout(function(){
                deferred.resolve(value);
            },500);
        }).promise();

    },

    manipulateRemoteData : function(url) {
        return $.Deferred(function(deferred) {
            $.getJSON(url, function(data) {
                var people = [];
                for (var i=0; i<data.people.length; i++) {
                    people.push(data.people[i].name);
                }
                deferred.resolve(people.sort());
            });
        }).promise();
    }

It appears that within the async function, when setTimeout() is firing after 200 milleseconds or so, three tests will appear under the "Async Behavior" section, one failing. The message tells me "you should understand how to use promises to handle asynchronicity", yet the error is specifically "Uncaught expected 0 to deeply equal 5..."

Is this a bug, or am I missing something?

Typo in flowControl.js

Simple thing:

  // if the number is divisible the 3 and 5, the function should return
  // 'fizzbuzz';

I assume you want: "if the number is divisible by 3 and 5, ..."

minify browser deps?

performance really isn't an issue and i think non-minified is helpful for debugging. mostly 100% on no here but thought i'd ask

Command line runner

I haven't looked into what will be involved to get this working, and I'm unclear whether using RequireJS is going to make it more complex. But being able to just run the tests on the command line rather than in a browser would be sweet.

error when I npm start

Server running 127.0.0.1:4444...
events.js:85
throw er; // Unhandled 'error' event
^
Error: listen EADDRINUSE
at exports._errnoException (util.js:746:11)
at Server._listen2 (net.js:1156:14)
at listen (net.js:1182:10)
at net.js:1280:9
at dns.js:85:18
at process._tickCallback (node.js:355:11)
at Function.Module.runMain (module.js:503:11)
at startup (node.js:129:16)
at node.js:814:3

npm ERR! Darwin 14.5.0
npm ERR! argv "node" "/usr/local/bin/npm" "start"
npm ERR! node v0.12.7
npm ERR! npm v2.12.1
npm ERR! code ELIFECYCLE
npm ERR! [email protected] start: node index.js
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] start script 'node index.js'.
npm ERR! This is most likely a problem with the js-assessment package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! node index.js
npm ERR! You can get their info via:
npm ERR! npm owner ls js-assessment
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:

Remove Item from Array Missing Argument?

In the Arrays test the test "you should be able to add the values of an array" has

expect(fn(a)).to.be(10);

So here fn(a) should return a number. But in the next test, "you should be able to remove an item from an array"

 var result = fn(a);

Here it is assumed that the result should be an array and you're are expected to remove "2" from the array but that has to be hardcoded into "fn" as the value "2" is not known to "fn."

Is this part of the test and is just a curveball or is it a typo?

bump to 0.3.0

i think we probs should, after removing require #108 , adding browser deps to package.json #106 , and then fixing #97. these are real large changes.

thoughts @jmeas?

ambiguous language

The third and fourth array tests have a subtle shift in language that can make the test hint unclear:

you should be able to remove a value from an array

My first thought was that the test was expecting one element to be removed, but the test assertion is looking for all elements with the given value to be removed.

Not a large issue, but something to be mindful of when running through the tests yourself, or when recommending the suite to someone ramping up on javascript.

speak function does not return anything

on line 16 of tests/app/functions.js - the test cannot be made to pass without altering this line to have the speak function return the result of sayIt instead of just running it.

Best Practices: parseInt hex testing wrong?

The parseInt tests has this as a test.

expect(bestPracticesAnswers.parseInt('0x12')).to.eql(0);

I'm not sure I see why it should be 0 though, if you have 0x at the beginning of a string for parseInt it'll treat it as a hexadecimal value. Shouldn't this be done differently?

Async remote data test

The test case for remote data expects 'Adem Alex Matt Paul Rebecca'.

The testdata.json has the last name listed as 'Adam'.

Is part of the test to manipulate the name 'Adam' to 'Adem' or is this a typo?

Improvements for the README file

Unless I'm mistaken... NPM gets installed with Node, so the instruction to also install NPM after installing node seems to be redundant -- or else out of date...? Also to get the npm install command to work, I had to restart (on Windows 7). Maybe worth mentioning that for those who aren't as familiar with this sort of thing. If you install node, then try to run that command without restarting, it produces an error.

Ensure tests work in browser and node

npm test does not currently work. The assessment tests should be able to be run both in the browser, and from the command line with the npm test command.

async test description

In the description of the second test for async behavior it's not mentioned that a structure of the response is response.people (not response.guys or whatever).

test description

The 3th test description from arrays is "you should be able to add the values of an array" but should be "you should be able to sum the items of an array"

rewrite with updated dependencies

would like to rewrite the scaffolding of this app with updated dependencies

  • up to Express 4.x
  • redo server/livereload with connect and watch in grunt
  • update mocha, maybe replace expect with chai

the old deps are making the app behave strangely in newer versions of node (#97). i start working on this in #98 and realized that to do this right, the best option would be to update all the deps.

i estimate this will take me a day. after we do this, we can bump up the version of this js-assessment package to 0.2.0. i'm pretty sure that the interface of the application can remain basically unchanged, except we won't use node bin/serve, but probably a more classic node index.js, or npm start so users shouldn't see much change expect for bugs disappearing.

thoughts, @rmurphey @jmeas @kadamwhite ?

A sort of sections on page refresh

every time i refresh, i have to find my section again that i was working on, which is sometimes not an easy feat...maybe a sort applied to the sections of testing?

Include Advanced Extra-Credit tests

Perhaps we can consider adding new tests where the user can complete several tests that have a much higher difficulty. For example:

  1. Arrays -> Sorting algorithms
  2. Strings -> Regex

Testing dojo skills

It would be very nice, if dojo or other libraries could be optionally included, and we could use this js-assessment to test also library skills not only basic JS.

Any ideas how to include it in non destructive way ?

about adding TDD styled tests

I really like this project and it's probably one of the best resources of testing assessment.

Although, I would like to have the same tests in a "TDD style" (is there a name for it?).

I'm not thinking about a total replacement, it won't be a solution, but there's two reasonable options to discuss:

  1. Add another dir with the same tests now with TDD styles.
  2. Fork and replace (in the fork)

For the new style I don't have a specific preference, it may be anything like QUnit, Mocha (in TDD api), Substack's Tape, etc.


Edit: the goal is to also improve testing assessment in more freedom of expression. Tests are great in any code style.

js-koans: in-browser experience

as referenced in #129, and mentioned in several convos with @rmurphey and @jmeas, i'm interested in building out a full in-browser experience for js-assessment.

inspiration originally comes from ruby-koans. http://rubykoans.com/

ruby koans supports both a CLI tool and an in-browser exp.

because this interface would require both this and the answers repository, i think i would propose creating a new repo for this. potentially called js-koans.

as our audience is dually beginners and employers/interviewers, my thought is that this would be a interface that a beginner could use alone, and a interviewer could pair on with an interviewee.

partially bringing this up now as i have an opportunity to work on this with some folks with mozilla next week but want to get community input before diving in. so share your thoughts!

Error After installing the js assessment

I'm receiving the error message I've below en in the page after installing successfully.

Error: global leak detected: myObject
at Runner.require.register.Runner.checkGlobals (http://localhost:4444/tests/libs/mocha.js:3453:21)
at Runner.require.register.Runner.constructor (http://localhost:4444/tests/libs/mocha.js:3371:44)
at Runner.require.register.EventEmitter.emit (http://localhost:4444/tests/libs/mocha.js:235:20)
at require.register.Runner.runTests.next (http://localhost:4444/tests/libs/mocha.js:3673:16)
at Test.require.register.Runnable.run (http://localhost:4444/tests/libs/mocha.js:3320:5)
at Runner.require.register.Runner.runTest (http://localhost:4444/tests/libs/mocha.js:3624:10)
at require.register.Runner.runTests.next (http://localhost:4444/tests/libs/mocha.js:3668:12)
at next (http://localhost:4444/tests/libs/mocha.js:3552:14)
at require.register.Runner.hooks (http://localhost:4444/tests/libs/mocha.js:3561:7)
at next (http://localhost:4444/tests/libs/mocha.js:3509:23)

contributors guide

as a first step to solving #129, after a long convo with @jmeas, i think creating a very specific contributing guide at CONTRIBUTING.md will help clarify both for ourselves and potential contributors what further extensions of js-assessment should be.

in keeping with rmurphey/js-assessment-answers#31 re: style, i think that we should also focus on the technical details and styles of contributions in this doc

arrays.remove, arrays.removeWithoutCopy redundancy?

Am I misunderstanding something, or are these two(remove, removeWithoutCopy) expecting essentially the same thing?

remove, currently and as I understand it, expects you to remove all elements equal to the "item" parameter in the array. Rather than simply removing the element at index "item", which doesn't seem to pass the test(which is what I initially thought it was asking for)

removeWithoutCopy seems to expect the exact same thing, but with the addition that you return the same array instance.

However, and I may be wrong, isn't that exactly what happens with the "answer" to the remove function as well?

README.md is incorrect

According to the current README.md file, here are the instructions for working on the tests.

"To do this, you'll need to edit the files in the tests/app directory."

But the actual instructions are in the help.txt file.

"The tests are in files in the tests/app directory; you will need to fill out the answers in the corresponding files in the app directory, reloading your browser to see whether the tests are passing."

Can you update the README file with the new instructions?

numbers.js :: convertToBinary question

Hey, first off - absolutely love this. Appreciate the work everyone has put in to it. I'm about 3/4 of the way through, and have learned a lot about what I know, know well, and don't know at all. So thanks!

This issue is more of a "question" (unable to tag as such) so perhaps not the best place to put it. It may be better to place it on the answers repo; let me know.

For the convertToBinary function, simply using num.toString(2) doesn't pass both of the tests. The reason is that 65 comes back as "1000001" - and I'm wondering if someone can explain why the "you should be able to" answer is different from the seemingly obvious, simple answer. I did look the answer up, but did not want to check it in as test passing code until I understood why, then how first...

Examples
var num = 65;
var bin = num.toString(2); // 1000001
console.log(parseInt(bin, 2)); // 65

// tests
expect(answers.convertToBinary(128)).to.eql('10000000'); // works with above code
expect(answers.convertToBinary(65)).to.eql('01000001'); // does not work with above code

Can someone explain what I'm learning so I can try to work the Google-Fu? Very much appreciated!

Best practices: declare functions safely passes by default on Firefox

Browser: Firefox 41.0.2

The current default implementation of exports.bestPracticesAnswers.functions passes without any modifications when I expect it to fail. This is because Fx doesn't hoist function declarations within blocks, which I believe is technically correct according to the ECMA specs (only statements within blocks) but contrary to most other browsers. Not sure how to fix this really.

More info here:

chmod +x bin/serve

This is such a small thing that I don't even want to create a pull request.

Right now the bin/serve script is not executable when you clone the repo, so either chmod +x bin/serve should be added to the README or you should check in an executable version.

Otherwise it looks great and I'm looking forward to improving my javascript-fu!

multiple assignment in tests confuses beginners

particularly in the functions section, speak step, this code was very confusing:

var speak = function() {
            return sayIt(this.greeting, this.name, '!!!');
          },
          obj = {
            greeting : 'Hello',
            name : 'Rebecca'
          };

simple changing it to this made it way easier to understand:

var speak = function() {
            return sayIt(this.greeting, this.name, '!!!');
          };
var obj = {
            greeting : 'Hello',
            name : 'Rebecca'
          };

Wrong hex number

Hello, i have question about parseInt function in section "best practices".

Shouldn't expect(answers.parseInt('0x12')).to.eql(0); look more like expect(answers.parseInt('0x12')).to.eql(18);?

Problem with installation

Hello,
I have a problem with installation of this package on Ubuntu Server. Once I enter 'npm install' some of dependencies are downloaded but when it achive requirejs I'm getting this error:

ERR! Error: UNKNOWN, symlink '../requirejs/bin/r.js'
ERR! You may report this log at:
ERR! http://github.com/isaacs/npm/issues
ERR! or email it to:
ERR! [email protected]
ERR!
ERR! System Linux 3.0.0-12-server
ERR! command "node" "/usr/local/bin/npm" "install"
ERR! cwd /media/sf_www/js-assessment
ERR! node -v v0.6.15
ERR! npm -v 1.1.16
ERR! path ../requirejs/bin/r.js
ERR! code UNKNOWN
ERR! message UNKNOWN, symlink '../requirejs/bin/r.js'
ERR! errno {}
verbose exit [ 1, true ]

Tests order is random

Yes, I think using requirejs is overkill for this purpose. It is causing more overhead then it is worth. Whether you use it or not, the way it is used right now doesn't work well because it even uses requirejs to load the test suites and as it does so asynchronously - as a result the tests arrive in a random order.

This makes it rather annoying when "taking" the test, as every time I load the page the top-most failing test is from another test suite. It is unworkable this way to work my way through it.

Tests not loading in browser

With the current master commit (4e39dc5), loading up localhost:4444 gives a blank page. The following is logged in Chrome dev tools console:

Navigated to http://localhost:4444/
(index):15 GET http://localhost:4444/node_modules/jquery/dist/jquery.js
(index):17 GET http://localhost:4444/node_modules/chai/chai.js
(index):22 Uncaught ReferenceError: chai is not defined(anonymous function) @ (index):22
arrays.js:6 Uncaught ReferenceError: describe is not defined(anonymous function) @ arrays.js:6
async.js:6 Uncaught ReferenceError: describe is not defined(anonymous function) @ async.js:6
bestPractices.js:6 Uncaught ReferenceError: describe is not defined(anonymous function) @ bestPractices.js:6
count.js:13 Uncaught ReferenceError: describe is not defined(anonymous function) @ count.js:13
flowControl.js:6 Uncaught ReferenceError: describe is not defined(anonymous function) @ flowControl.js:6
functions.js:6 Uncaught ReferenceError: describe is not defined(anonymous function) @ functions.js:6
logicalOperators.js:6 Uncaught ReferenceError: describe is not defined(anonymous function) @ logicalOperators.js:6
modules.js:6 Uncaught ReferenceError: describe is not defined(anonymous function) @ modules.js:6
numbers.js:6 Uncaught ReferenceError: describe is not defined(anonymous function) @ numbers.js:6
objects.js:6 Uncaught ReferenceError: describe is not defined(anonymous function) @ objects.js:6
recursion.js:7 Uncaught ReferenceError: describe is not defined(anonymous function) @ recursion.js:7
regex.js:6 Uncaught ReferenceError: describe is not defined(anonymous function) @ regex.js:6
(index):56 GET http://localhost:35729/livereload.js net::ERR_CONNECTION_REFUSED

Did a bisect and the first bad commit is ce191d1

TDD: Game of Life

So Conway's GoF, it's even kind of tradition at CodeRetreats to have (1) a list of tests and make code pass one more test each iteration. Make a commit each iteration.
Or the other way - (2) you have many iterations of code and you gotta create tests, add one test per each iteration.

If you're okay with that, I'll push it when I have a few spare hours. You do both at CodeReatreat, but (1) sounds more convincing to me in this case.

Move the code that makes the tests pass out of the tests themselves

A couple people have mentioned this, and I think it's a good idea, but not sure how best to go about it. I'm thinking that the app directory would have filenames that match the names of the files in tests/app, and that each file in app would return an object with methods that would be called in the tests. So, app/arrays.js would be something like:

define([ 'use!underscore' ], function(_) {
  return {
    locateItemInArray : function(arr, item) {
      // user would be expected to fill this in
    },
    // ...
  };
});

Thoughts?

Command "npm test" filed

Error when running tests on the command line (npm test):

C:\Temp\js-assessment\node_modules\mocha\lib\utils.js:634
        throw new Error("cannot resolve path (or pattern) '" + path + "'");
        ^

Error: cannot resolve path (or pattern) ''tests/app''
    at Object.lookupFiles (C:\Temp\js-assessment\node_modules\mocha\lib\utils.js              :634:15)
    at C:\Temp\js-assessment\node_modules\mocha\bin\_mocha:327:30
    at Array.forEach (native)
    at Object.<anonymous> (C:\Temp\js-assessment\node_modules\mocha\bin\_mocha:3              26:6)
    at Module._compile (module.js:409:26)
    at Object.Module._extensions..js (module.js:416:10)
    at Module.load (module.js:343:32)
    at Function.Module._load (module.js:300:12)
    at Function.Module.runMain (module.js:441:10)
    at startup (node.js:139:18)
    at node.js:968:3
npm ERR! Test failed.  See above for more details.

array: duplicates function unclear

What should the duplicates function return?

  1. All values in the array that have more than 1 occurrence.
  2. All values that are left over after stripping away the first occurrence.

Examples:

  1. [1, 1, 1, 4, 2, 2].duplicates = [1, 2]
  2. [1, 1, 1, 4, 2, 2].duplicates = [1, 1, 2]

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.