Skip to content

Commit af05bf7

Browse files
jtennerdcodeIO
authored andcommitted
Set up testing (#1)
1 parent a4dac9f commit af05bf7

File tree

14 files changed

+504
-8
lines changed

14 files changed

+504
-8
lines changed

.travis.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
language: node_js
2+
notifications:
3+
email: false
4+
before_install: npm config set progress=false && npm i -g npm@latest --no-audit
5+
install: npm ci --no-audit
6+
jobs:
7+
include:
8+
- node_js: lts/*
9+
script:
10+
- npm test
11+
env: Runs the tests on node.js LTS.
12+
- node_js: node
13+
script:
14+
- npm test
15+
env: Runs the tests on node.js Stable.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
![AS](https://avatars1.githubusercontent.com/u/28916798?s=48) node
22
======================
33

4-
Implementations of the node.js APIs for use with AssemblyScript.
4+
Implementations of the node.js APIs using wasi for use with AssemblyScript.

assembly/buffer/index.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
1-
// TODO
1+
export class Buffer extends Uint8Array {
2+
constructor(size: i32) {
3+
super(size);
4+
}
5+
}

assembly/fs/index.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,13 @@
1-
// TODO
1+
import { Buffer } from "../buffer";
2+
3+
/**
4+
* TODO: Look at https://nodejs.org/dist/latest-v12.x/docs/api/fs.html#fs_fs_readfilesync_path_options
5+
*
6+
* Path can be `<string> | <Buffer> | <URL> | <integer>`.
7+
*
8+
* This will require a `<T>` parameter to handle all these cases. In this particular case, I think
9+
* it's okay to default to only `<string>`.
10+
*/
11+
export function readFileSync(): Buffer {
12+
return new Buffer(0);
13+
}

assembly/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
// TODO: Set up globals, like Buffer
1+
export { Buffer } from "./buffer";

assembly/node.d.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
declare class Buffer extends Uint8Array {
2+
3+
}

assembly/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"extends": "../../next/std/assembly.json",
2+
"extends": "../node_modules/assemblyscript/std/assembly.json",
33
"include": [
44
"./**/*.ts"
55
]

package-lock.json

Lines changed: 275 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"description": "Implementations of the node.js APIs for use with AssemblyScript.",
44
"version": "0.1.0",
55
"license": "Apache-2.0",
6+
"types": "assembly/node.d.ts",
67
"repository": {
78
"type": "git",
89
"url": "https://github.com/AssemblyScript/node.git"
@@ -11,9 +12,14 @@
1112
"url": "https://github.com/AssemblyScript/node/issues"
1213
},
1314
"devDependencies": {
14-
"assemblyscript": "github:AssemblyScript/assemblyscript"
15+
"@as-pect/core": "^2.2.0",
16+
"assemblyscript": "github:assemblyscript/assemblyscript#7c775d1bccbe08fec5d820b9d53ae44ff6bd1e49",
17+
"diff": "^4.0.1",
18+
"glob": "^7.1.4",
19+
"wasi": "github:devsnek/node-wasi"
1520
},
1621
"scripts": {
17-
"test": "node tests"
18-
}
22+
"test": "node tests/node"
23+
},
24+
"dependencies": {}
1925
}

tests/buffer.spec.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/**
2+
* This is the buffer test suite. For each prototype function, put a single test
3+
* function call here.
4+
*
5+
* @example
6+
* describe("buffer", () => {
7+
* test("#alloc", () => {
8+
* // put any expectations related to #alloc here
9+
* });
10+
* });
11+
*/
12+
13+
describe("buffer", () => {
14+
test("#constructor", () => {
15+
expect<Buffer>(new Buffer(0)).toBeTruthy();
16+
expect<Buffer>(new Buffer(10)).toHaveLength(10);
17+
let myBuffer = new Buffer(10);
18+
expect<ArrayBuffer>(myBuffer.buffer).toBeTruthy();
19+
expect<ArrayBuffer>(myBuffer.buffer).toHaveLength(10);
20+
});
21+
});

0 commit comments

Comments
 (0)