Skip to content

Commit

Permalink
Added tests
Browse files Browse the repository at this point in the history
  • Loading branch information
syrusakbary committed Oct 11, 2019
1 parent 0452c24 commit b9ac0f7
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
"build": "npm run build:library && npm run build:readme && npm run fmt",
"build:website": "npm run build && node genwebsite.js",
"build:website:netlify": "./build.sh",
"fmt": "prettier --write ./{,{src,rollup-plugins}/**/}*.{mjs,js,md}"
"fmt": "prettier --write ./{,{src,rollup-plugins}/**/}*.{mjs,js,md}",
"fmt_test": "test $(prettier -l ./{,{src,rollup-plugins}/**/}*.{mjs,js,md} | wc -l) -eq 0",
"test": "npm run fmt_test && npm run build && node --no-warnings test/index.js"
},
"repository": "GoogleChromeLabs/wasm-feature-detect",
"keywords": [],
Expand Down
45 changes: 45 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/**
* Copyright 2019 Google Inc. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

const assert = require('assert');

process.on("unhandledRejection", err => {
throw err;
});

// We try to import the generated module
const features = require(__dirname+'/../dist/cjs');

const isBoolean = function (value) {
return value === true || value === false;
}

const checkFeature = function (featureName) {
const feature = features[featureName];
assert(feature, `The feature ${featureName} doesn't exist`);
feature().then(function(result) {
console.log(`The feature ${featureName} returned: ${result}`);
assert(isBoolean(result), `The feature ${featureName} returned: ${result}`);
})
}

checkFeature("bulkMemory");
checkFeature("exceptions");
checkFeature("multiValue");
checkFeature("mutableGlobals");
checkFeature("referenceTypes");
checkFeature("saturatedFloatToInt");
checkFeature("signExtensions");
checkFeature("simd");
checkFeature("tailCall");
checkFeature("threads");

0 comments on commit b9ac0f7

Please sign in to comment.