Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
aspeddro committed Feb 11, 2024
1 parent 51a4c84 commit e171514
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 48 deletions.
1 change: 1 addition & 0 deletions .github/workflows/doc-examples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ jobs:
with:
node-version: 18
- run: npm install
- run: npm build
- run: npm run test-doc-examples
8 changes: 1 addition & 7 deletions bindings/Node.res
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,10 @@ module Fs = {
@module("fs") external readdirSync: string => array<string> = "readdirSync"
@module("fs") external writeFileSync: (string, string) => unit = "writeFileSync"
@module("fs") external mkdirSync: string => option<string> = "mkdirSync"
@module("fs") external existsSync: string => bool = "existsSync"
@module("node:fs/promises") external writeFile: (string, string) => promise<unit> = "writeFile"
@module("node:fs/promises") external unlink: string => promise<unit> = "unlink"
@module("fs") external existsSync: string => bool = "existsSync"

type statSync
@module("fs") external statSync: string => statSync = "statSync"

@module("node:fs/promises") external lstat: string => promise<'a> = "lstat"

@send external isDirectory: statSync => bool = "isDirectory"
}

module Buffer = {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"build": "rescript",
"watch": "rescript build -w",
"test": "node test/TestSuite.mjs && node test/TempTests.mjs",
"test-doc-examples": "rescript && node scripts/ExamplesTest.mjs"
"test-doc-examples": "node scripts/ExamplesTest.mjs"
},
"keywords": [
"rescript"
Expand Down
46 changes: 20 additions & 26 deletions scripts/ExamplesTest.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -137,32 +137,24 @@ async function testCodeBlock(id, _kind, code) {
resolve(stderr);
}));
}));
var fileExists = async function (file) {
var removeFile = async function (file) {
return await Core__Promise.$$catch(Promises.lstat(file).then(function (param) {
return true;
Promises.unlink(file);
}), (function (param) {
return Promise.resolve(false);
return Promise.resolve();
}));
};
await Promise.all([
".res",
".cmj",
".cmt",
".cmi"
].map(async function (extension) {
var path = tempFileName + extension;
var exists = await fileExists(path);
if (!exists) {
return ;
}
try {
Promises.unlink(path);
return ;
}
catch (exn){
return ;
}
}));
var buildFilesExtensions = [
".res",
".cmj",
".cmt",
".cmi"
];
await Promise.all(buildFilesExtensions.map(async function (extension) {
return await removeFile(tempFileName + extension);
})).then(function (param) {

});
if (promise.length <= 0) {
return {
TAG: "Ok",
Expand Down Expand Up @@ -307,10 +299,12 @@ function getCodeBlocks(example) {
}

var tests = getDocstrings(extractDoc("src/RescriptCore.res")).map(function (doc) {
return [
doc,
getCodeBlocks(doc)
];
return [
doc,
getCodeBlocks(doc)
];
}).filter(function (param) {
return param[1].length > 0;
});

var moduleTestsResults = await Promise.all(tests.map(async function (param) {
Expand Down
28 changes: 14 additions & 14 deletions scripts/ExamplesTest.res
Original file line number Diff line number Diff line change
Expand Up @@ -123,21 +123,20 @@ let testCodeBlock = async (id, _kind, code) => {
})
})

let fileExists = async file =>
await Fs.lstat(file)->Promise.thenResolve(_ => true)->Promise.catch(_ => Promise.resolve(false))

let _ =
await [".res", ".cmj", ".cmt", ".cmi"]
->Array.map(async extension => {
let path = tempFileName ++ extension
let exists = await fileExists(path)
if exists {
try {Fs.unlink(path)->ignore} catch {
| _ => ()
}
}
let removeFile = async file =>
await Fs.lstat(file)
->Promise.thenResolve(_ => {
Fs.unlink(file)->ignore
})
->Promise.all
->Promise.catch(_ => Promise.resolve())

let buildFilesExtensions = [".res", ".cmj", ".cmt", ".cmi"]

await Array.map(buildFilesExtensions, async extension => {
await removeFile(tempFileName ++ extension)
})
->Promise.all
->Promise.thenResolve(_ => ())

switch Array.length(promise) > 0 {
| true =>
Expand Down Expand Up @@ -237,6 +236,7 @@ let tests =
extractDoc("src/RescriptCore.res")
->getDocstrings
->Array.map(doc => (doc, doc->getCodeBlocks))
->Array.filter(((_, b)) => Array.length(b) > 0)

let moduleTestsResults =
await tests
Expand Down

0 comments on commit e171514

Please sign in to comment.