You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<p> Recall that this line, among other things, checks if <code>this</code> is an Object, therefore we can test it by trying it on non-objects.
1493
-
Primitive types in JavaScript™ are not considered objects.
1494
-
So an example of the tests you can write for this, could look like this:</p>
1481
+
The <ahref="https://github.com/tc39/test262/blob/main/CONTRIBUTING.md#acceptable-tests">official guidelines</a> state that an acceptable test in Test262 is the following:</p>
1482
+
<blockquote>
1483
+
<p><em>Any test that exercises observable grammar or semantics, originating with citable, normative text in the latest draft of the ECMAScript® Language Specification, the ECMAScript® Internationalization API Specification, the The JSON Data Interchange Syntax, a Stage 3 proposal or a Pull Request which makes a normative change to any of those specifications.</em></p>
1484
+
</blockquote>
1485
+
<p> The key point for this is that we should write tests for any observable grammar or semantic from our specification.</p>
1486
+
<p> First, we need to identify the so-called <em>testable lines</em> in our specification.
1487
+
One way to think about it is this: whenever the behaviour of the specification is observable to the user, then it is testable.</p>
1488
+
<p> An example of an easily testable line in our specification is:</p>
<p> Recall that this line, among other things, checks whether <code>this</code> is an <code>Object</code>. Therefore, we can test it by trying it on non-objects, for example, on <ahref="https://262.ecma-international.org/#sec-primitive-value">values of primitive types</a>.
1492
+
Here is an example of a test where we assert that calling the <code>upsert</code> method on <code>false</code> with arguments <code>1</code> and <code>1</code> will throw <code>TypeError</code> exception:</p>
1495
1493
<pre><codeclass="language-js">var m = new Map();
1496
1494
1497
1495
assert.throws(TypeError, function () {
1498
1496
m.upsert.call(false, 1, 1);
1499
1497
});
1500
1498
</code></pre>
1501
-
<p> The <code>assert</code> is part of the Test262 suite, here we assert that a TypeError is thrown.</p>
1502
-
<p> You can find the rest of the functions for assert <ahref="https://github.com/tc39/test262/blob/main/CONTRIBUTING.md#test-environment" target="_blank">here</a>.</p>
1503
-
<h3id="more-than-just-testing">More than just testing</h3>
1504
-
<p> Additional to the tests, there is a strict guide for documentation for the test.</p>
1505
-
<p> You start the test by declaring the copyright, here you just fill in the year and your name:</p>
1499
+
<p> The <code>assert</code> method is a part of the Test262 suite. You can find the rest of the functions for assert <ahref="https://github.com/tc39/test262/blob/main/CONTRIBUTING.md#test-environment" target="_blank">here</a>.</p>
1500
+
<h3id="more-than-just-testing">More Than Just Testing</h3>
1501
+
<p> Test262 test should be documented in a <ahref="https://github.com/tc39/test262/blob/main/CONTRIBUTING.md#test-case-style">certain manner</a>. </p>
1502
+
<p> We start with stating the copyright:</p>
1506
1503
<pre><code>// Copyright (C) *Year *Name. All rights reserved.
1507
1504
// This code is governed by the BSD license found in the LICENSE file.
1508
1505
</code></pre>
1509
-
<p> The rest of the information is enclosed in a YAML string and has specified values to simplify parsing.
1510
-
All the info is inside the YAML tags <code>/*---</code> and <code>---*/</code>.</p>
1511
-
<p> We start with the required key <code>esid</code>, which is the ECMAScript® identifier.
1512
-
This doesn't apply to us yet, as the proposal hasn't gotten one, therefore we will use <code>pending</code>.</p>
1506
+
<p> The rest of the test meta-information is enclosed in a YAML string and mentions specific fields ("keys), some of which we explain in the table below.
1507
+
The complete list of possible keys can be found <ahref="https://github.com/tc39/test262/blob/main/CONTRIBUTING.md#frontmatter" target="_blank">here</a>.</p>
1508
+
<tableclass="styled-table">
1509
+
<thead>
1510
+
<tr>
1511
+
<th>field</th>
1512
+
<th>explanation</th>
1513
+
</tr>
1514
+
</thead>
1515
+
<tbody><tr>
1516
+
<td><code>esid</code></td>
1517
+
<td>reference to specification section, e.g. <code>sec-well-known-symbols</code></td>
1518
+
</tr>
1519
+
<tr>
1520
+
<td><code>description</code></td>
1521
+
<td>short one-line description stating the purpose of the test, e.g., "Throws a TypeError if <code>this</code> is not an object"</td>
1522
+
</tr>
1523
+
<tr>
1524
+
<td><code>info</code></td>
1525
+
<td>verbose description of the test mentioning, e.g., what does the method look like, which line of code are we testing, etc.</td>
1526
+
</tr>
1527
+
</tbody></table>
1528
+
<p> For our <code>upsert</code> specification, the required key <code>esid</code> is not applicable yet, as (at the time of writing) the proposal hasn't gotten one. Therefore, we will use <code>pending</code>.</p>
1513
1529
<pre><code>esid: pending
1514
1530
</code></pre>
1515
-
<p> Next comes the description which is the other required key.
1516
-
The description should be short and on one line regarding the purpose of this testcase.
1517
-
In our case, it will look something like: </p>
1531
+
<p> Next comes the <code>description</code> key. In our case, it will look like this: </p>
1518
1532
<pre><code>description: >
1519
1533
Throws a TypeError if 'this' is not an object
1520
1534
</code></pre>
1521
-
<p> Although not required, we should fill out the <code>info</code> key as well.
1522
-
Some points that are beneficial here are:
1523
-
- What does the method look like?
1524
-
- Which line of code are we testing?</p>
1535
+
<p> Although not required, we fill out the <code>info</code> key as well:</p>
1525
1536
<pre><code>info: |
1526
1537
Map.upsert( key , value )
1527
1538
1528
-
1. Let M be the this value
1529
-
2. Perform ? RequireInternalSlot(M, [[MapData]])
1539
+
1. Let M be the this value.
1540
+
2. Perform ? RequireInternalSlot(M, [[MapData]]).
1530
1541
...
1531
1542
</code></pre>
1532
-
<p> There are many other keys we can look at, but if you want to learn more about them, check out this <ahref="https://github.com/tc39/test262/blob/main/CONTRIBUTING.md#frontmatter" target="_blank">link.</a></p>
1533
-
<p> Our full test should now look something like this:</p>
1543
+
<p> Our full test should now look as follows:</p>
1534
1544
<pre><codeclass="language-js">// Copyright (C) 2024 Sune Eriksson Lianes. All rights reserved.
1535
1545
// This code is governed by the BSD license found in the LICENSE file.
1536
1546
/*---
@@ -1550,8 +1560,8 @@ <h3 id="more-than-just-testing">More than just testing</h3>
1550
1560
m.upsert.call(false, 1, 1);
1551
1561
});
1552
1562
</code></pre>
1553
-
<h3id="fill-in-test-cases">Fill in test cases</h3>
1554
-
<p> We can now fill in with other test cases (non-objects):</p>
1563
+
<h3id="filling-in-test-cases">Filling in Test Cases</h3>
1564
+
<p> We can now fill in other test cases related to calling <code>upsert</code> on non-objects:</p>
1555
1565
<pre><codeclass="language-js">// Copyright (C) 2024 Sune Eriksson Lianes. All rights reserved.
1556
1566
// This code is governed by the BSD license found in the LICENSE file.
1557
1567
/*---
@@ -1592,12 +1602,14 @@ <h3 id="fill-in-test-cases">Fill in test cases</h3>
1592
1602
m.upsert.call(Symbol(), 1, 1);
1593
1603
});
1594
1604
</code></pre>
1595
-
<p> You can take a look at other tests written in the test262 folder or try to write some tests yourself.</p>
1596
-
<h3id="running-tests-in-spidermonkey">Running tests in SpiderMonkey</h3>
1597
-
<p> To add the test you simply create the file in <code>mozilla-unified/js/src/tests/test262/built-ins/Map/</code>.
1598
-
Preferably creating a folder for the proposal as well.</p>
1599
-
<p> When this is done, you can run the tests with <code>./mach jstests built-ins/Map</code>, or be even more specific if you have created a folder.</p>
1600
-
<p> You will then see something like this, depending on how many tests are run:</p>
1605
+
<p> You can take a look at other tests in the <ahref="/test262"><code>test262</code></a> folder or try to write some tests yourself.</p>
1606
+
<h3id="running-tests-in-spidermonkey">Running Tests in SpiderMonkey</h3>
1607
+
<p> To add a test, we create a file with the test in <code>mozilla-unified/js/src/tests/test262/built-ins/Map/</code>.
1608
+
It makes sense to create a folder for all the tests related to the proposal.</p>
0 commit comments