Getting familiar with JavaScript Open Standards

This week i have been introduced to open standards and JavaScript testing under ECMAScript standard. In this lab i will walk through some tests in order to better understand how testing works and what it takes to build own tests. JavaScript open standards is a set of rules that have to be followed in order for the technology work as expected globally regardless of the development environment, product type, etc. To build and run the JavaScript tests i use Test262-Harness, which allows us to run ECMAScript using Node.js.

First, lets get familiar with Tests by reading CONTRIBUTING.md and README.md. This documentation provided on GitHub is a good place to start with since it provides the information necessary to understand the testing process, tools and scripting features that you have newer previously worked with.

Now we can install Harness by executing the following instructions:

git clone https://github.com/tc39/test262.git --depth 1
cd test262
npm install -g test262-harness

Note that the above commands have to be run in terminal if you are using MacOS or Git Bash if you are using Windows. Also do not forget to have up to date version of Node.js installed.

Once the harness is installed it is a good idea to execute the tests downloaded to check current status of the tests (tests that pass of fail). You can execute the tests by running the below command from test262 folder:

test262-harness test/**/*.js

If  everything is Ok you should get the following:

Capture

As you can see 6 tests failed, which seems to be normal behavior based on what i have read in other students blog posts.

Prior to writing own test we need to get a general idea of the test specification we plan to work with. Meaning get familiar with script you are attempting to test, in my case i need to understand the implementation of Array.prototype.reverse(). This method simply reverses an array of elements.

Once you understand what reverse does we can write some tests to test certain use cases to make sure the reverse function behaves as expected. I decided to remake this test, which is already provided to us. The test logic is concise and simple, so making modification to the test was not very hard at all. In the file i noticed an if statement used to do the array comparison:

if (reverse !== x) {

$ERROR(#1: x = []; x.reverse() === x. Actual: + (reverse));

}

I decided to remove the if to do the comparison and output printing and use one line   sameValue()  assert module method to do the comparison and message printing. The function is straight forward and returns a Boolean if two arrays contain equal values. So, i basically simplified the initial test code to this:

assert.sameValue(x, reverse, ‘#2: x = []; x[0] = 1; x.reverse() === x. Actual: ‘ + (reverse));

I did that to all 6 tests and my test can be found here. The idea of the test is to go through some comparisons before and after reverse method is called to check if the reverse did what is expected and the function logic does not cause any issues.

Note that i have added my test to the ~/test262/test/test.js file and i run the test using test262-harness test/*.js command.

To conclude, today i have learned about open standards and what it means to contribute to open standards. Now i am familiar with the process, tools and some useful Technics to write and run automated tests using Harness. Also i once again learned new things from GitHub and about GitHub. I’ve also learned more about how JavaScript and how easy it is to understand and write tests.

Leave a comment