Skip to content

Commit ff001c1

Browse files
committed
test: move WPT to its own testing module
This is first in a hoped-for series of moves away from a monolithic common.js that is loaded for every test and towards a more modular approach. (In the end, common.js will hopefully contain checks for variables leaking into the global space and perhaps some of the more ubiquitous functions like common.mustCall().) Move the WPT testing code to its own module. PR-URL: #12736 Reviewed-By: Gibson Fahnestock <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Richard Lau <[email protected]>
1 parent eb535c5 commit ff001c1

22 files changed

+346
-328
lines changed

benchmark/http/http_server_for_chunky_client.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ var http = require('http');
55
var fs = require('fs');
66
var fork = require('child_process').fork;
77
var common = require('../common.js');
8-
var test = require('../../test/common.js');
8+
var test = require('../../test/common');
99
var pep = `${path.dirname(process.argv[1])}/_chunky_http_client.js`;
1010
var PIPE = test.PIPE;
1111

test/README.md

+9-280
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,13 @@
11
# Node.js Core Tests
22

3-
This folder contains code and data used to test the Node.js implementation.
3+
This directory contains code and data used to test the Node.js implementation.
44

55
For a detailed guide on how to write tests in this
66
directory, see [the guide on writing tests](../doc/guides/writing-tests.md).
77

88
On how to run tests in this direcotry, see
99
[the contributing guide](../CONTRIBUTING.md#step-5-test).
1010

11-
## Table of Contents
12-
13-
* [Test directories](#test-directories)
14-
* [Common module API](#common-module-api)
15-
1611
## Test Directories
1712

1813
<table>
@@ -48,6 +43,14 @@ On how to run tests in this direcotry, see
4843
C++ test that is run as part of the build process.
4944
</td>
5045
</tr>
46+
<tr>
47+
<td>common</td>
48+
<td></td>
49+
<td>
50+
Common modules shared among many tests.
51+
<a href="./common/README.md">[Documentation]</a>
52+
</td>
53+
</tr>
5154
<tr>
5255
<td>debugger</td>
5356
<td>No</td>
@@ -158,277 +161,3 @@ On how to run tests in this direcotry, see
158161
</tr>
159162
</tbody>
160163
</table>
161-
162-
## Common module API
163-
164-
The common.js module is used by tests for consistency across repeated
165-
tasks. It has a number of helpful functions and properties to help with
166-
writing tests.
167-
168-
### allowGlobals(...whitelist)
169-
* `whitelist` [&lt;Array>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array) Array of Globals
170-
* return [&lt;Array>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)
171-
172-
Takes `whitelist` and concats that with predefined `knownGlobals`.
173-
174-
### arrayStream
175-
A stream to push an array into a REPL
176-
177-
### busyLoop(time)
178-
* `time` [&lt;Number>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type)
179-
180-
Blocks for `time` amount of time.
181-
182-
### canCreateSymLink
183-
API to indicate whether the current running process can create
184-
symlinks. On Windows, this returns false if the process running
185-
doesn't have privileges to create symlinks (specifically
186-
[SeCreateSymbolicLinkPrivilege](https://msdn.microsoft.com/en-us/library/windows/desktop/bb530716(v=vs.85).aspx)).
187-
On non-Windows platforms, this currently returns true.
188-
189-
### crashOnUnhandledRejection()
190-
191-
Installs a `process.on('unhandledRejection')` handler that crashes the process
192-
after a tick. This is useful for tests that use Promises and need to make sure
193-
no unexpected rejections occur, because currently they result in silent
194-
failures.
195-
196-
### ddCommand(filename, kilobytes)
197-
* return [&lt;Object>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)
198-
199-
Platform normalizes the `dd` command
200-
201-
### enoughTestMem
202-
* return [&lt;Boolean>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type)
203-
204-
Check if there is more than 1gb of total memory.
205-
206-
### expectsError(settings)
207-
* `settings` [&lt;Object>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)
208-
with the following optional properties:
209-
* `code` [&lt;String>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type)
210-
expected error must have this value for its `code` property
211-
* `type` [&lt;Function>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function)
212-
expected error must be an instance of `type`
213-
* `message` [&lt;String>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type)
214-
or [&lt;RegExp>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp)
215-
if a string is provided for `message`, expected error must have it for its
216-
`message` property; if a regular expression is provided for `message`, the
217-
regular expression must match the `message` property of the expected error
218-
219-
* return function suitable for use as a validation function passed as the second
220-
argument to `assert.throws()`
221-
222-
The expected error should be [subclassed by the `internal/errors` module](https://github.com/nodejs/node/blob/master/doc/guides/using-internal-errors.md#api).
223-
224-
### expectWarning(name, expected)
225-
* `name` [&lt;String>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type)
226-
* `expected` [&lt;String>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type) | [&lt;Array>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)
227-
228-
Tests whether `name` and `expected` are part of a raised warning.
229-
230-
## getArrayBufferViews(buf)
231-
* `buf` [&lt;Buffer>](https://nodejs.org/api/buffer.html#buffer_class_buffer)
232-
* return [&lt;ArrayBufferView&#91;&#93;>](https://developer.mozilla.org/en-US/docs/Web/API/ArrayBufferView)
233-
234-
Returns an instance of all possible `ArrayBufferView`s of the provided Buffer.
235-
236-
### hasCrypto
237-
* return [&lt;Boolean>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type)
238-
239-
Checks for 'openssl'.
240-
241-
### hasFipsCrypto
242-
* return [&lt;Boolean>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type)
243-
244-
Checks `hasCrypto` and `crypto` with fips.
245-
246-
### hasIPv6
247-
* return [&lt;Boolean>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type)
248-
249-
Checks whether `IPv6` is supported on this platform.
250-
251-
### hasMultiLocalhost
252-
* return [&lt;Boolean>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type)
253-
254-
Checks if there are multiple localhosts available.
255-
256-
### fileExists(pathname)
257-
* pathname [&lt;String>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type)
258-
* return [&lt;Boolean>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type)
259-
260-
Checks if `pathname` exists
261-
262-
### fixturesDir
263-
* return [&lt;String>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type)
264-
265-
Path to the 'fixtures' directory.
266-
267-
### globalCheck
268-
* return [&lt;Boolean>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type)
269-
270-
Turn this off if the test should not check for global leaks.
271-
272-
### inFreeBSDJail
273-
* return [&lt;Boolean>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type)
274-
275-
Checks whether free BSD Jail is true or false.
276-
277-
### isAix
278-
* return [&lt;Boolean>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type)
279-
280-
Platform check for Advanced Interactive eXecutive (AIX).
281-
282-
### isAlive(pid)
283-
* `pid` [&lt;Number>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type)
284-
* return [&lt;Boolean>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type)
285-
286-
Attempts to 'kill' `pid`
287-
288-
### isFreeBSD
289-
* return [&lt;Boolean>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type)
290-
291-
Platform check for Free BSD.
292-
293-
### isLinux
294-
* return [&lt;Boolean>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type)
295-
296-
Platform check for Linux.
297-
298-
### isLinuxPPCBE
299-
* return [&lt;Boolean>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type)
300-
301-
Platform check for Linux on PowerPC.
302-
303-
### isOSX
304-
* return [&lt;Boolean>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type)
305-
306-
Platform check for macOS.
307-
308-
### isSunOS
309-
* return [&lt;Boolean>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type)
310-
311-
Platform check for SunOS.
312-
313-
### isWindows
314-
* return [&lt;Boolean>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type)
315-
316-
Platform check for Windows.
317-
318-
### isWOW64
319-
* return [&lt;Boolean>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type)
320-
321-
Platform check for Windows 32-bit on Windows 64-bit.
322-
323-
### leakedGlobals
324-
* return [&lt;Array>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)
325-
326-
Checks whether any globals are not on the `knownGlobals` list.
327-
328-
### localhostIPv4
329-
* return [&lt;String>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type)
330-
331-
Gets IP of localhost
332-
333-
### localIPv6Hosts
334-
* return [&lt;Array>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)
335-
336-
Array of IPV6 hosts.
337-
338-
### mustCall([fn][, expected])
339-
* fn [&lt;Function>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function)
340-
* expected [&lt;Number>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type) default = 1
341-
* return [&lt;Function>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function)
342-
343-
Returns a function that calls `fn`. If the returned function has not been called
344-
exactly `expected` number of times when the test is complete, then the test will
345-
fail.
346-
347-
If `fn` is not provided, `common.noop` will be used.
348-
349-
### nodeProcessAborted(exitCode, signal)
350-
* `exitCode` [&lt;Number>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type)
351-
* `signal` [&lt;String>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type)
352-
* return [&lt;Boolean>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type)
353-
354-
Returns `true` if the exit code `exitCode` and/or signal name `signal` represent the exit code and/or signal name of a node process that aborted, `false` otherwise.
355-
356-
### noop
357-
358-
A non-op `Function` that can be used for a variety of scenarios.
359-
360-
For instance,
361-
362-
<!-- eslint-disable strict, no-undef -->
363-
```js
364-
const common = require('../common');
365-
366-
someAsyncAPI('foo', common.mustCall(common.noop));
367-
```
368-
369-
### opensslCli
370-
* return [&lt;Boolean>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type)
371-
372-
Checks whether 'opensslCli' is supported.
373-
374-
### platformTimeout(ms)
375-
* `ms` [&lt;Number>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type)
376-
* return [&lt;Number>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type)
377-
378-
Platform normalizes timeout.
379-
380-
### PIPE
381-
* return [&lt;String>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type)
382-
383-
Path to the test sock.
384-
385-
### PORT
386-
* return [&lt;Number>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type) default = `12346`
387-
388-
Port tests are running on.
389-
390-
### refreshTmpDir
391-
* return [&lt;String>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type)
392-
393-
Deletes the 'tmp' dir and recreates it
394-
395-
### rootDir
396-
* return [&lt;String>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type)
397-
398-
Path to the 'root' directory. either `/` or `c:\\` (windows)
399-
400-
### skip(msg)
401-
* `msg` [&lt;String>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type)
402-
403-
Logs '1..0 # Skipped: ' + `msg`
404-
405-
### spawnPwd(options)
406-
* `options` [&lt;Object>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)
407-
* return [&lt;Object>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)
408-
409-
Platform normalizes the `pwd` command.
410-
411-
### spawnSyncPwd(options)
412-
* `options` [&lt;Object>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)
413-
* return [&lt;Object>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)
414-
415-
Synchronous version of `spawnPwd`.
416-
417-
### tmpDir
418-
* return [&lt;String>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type)
419-
420-
The realpath of the 'tmp' directory.
421-
422-
### tmpDirName
423-
* return [&lt;String>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type)
424-
425-
Name of the temp directory used by tests.
426-
427-
### WPT
428-
429-
A port of parts of
430-
[W3C testharness.js](https://github.com/w3c/testharness.js) for testing the
431-
Node.js
432-
[WHATWG URL API](https://nodejs.org/api/url.html#url_the_whatwg_url_api)
433-
implementation with tests from
434-
[W3C Web Platform Tests](https://github.com/w3c/web-platform-tests).

0 commit comments

Comments
 (0)