@smallstack/testing

functionality for testing smallstack projects/packages

Usage no npm install needed!

<script type="module">
  import smallstackTesting from 'https://cdn.skypack.dev/@smallstack/testing';
</script>

README

@smallstack/testing

To test your smallstack package, follow these steps:

  • add these packages as dev dependencies: npm install @smallstack/testing @types/chai @types/mocha chai jsdom karma karma-cli karma-jsdom-launcher karma-mocha karma-typescript mocha typescript --save-dev
  • add these two scripts to your package.json:
    • "test:ci": "karma start --single-run",
    • "test": "karma start"
  • (optional) add the test execution to your gitlab-ci.yml: - npm run test:ci
  • call npm install
  • (optional) create a /tests folder (you can also put the tests next to your source code)
  • create tests with the name SOMETHING.spec.ts and fill with mocha/chai testing code, see https://gitlab.com/smallstack/products/smallstack-common/tree/develop/tests
  • add a karma.conf.js file in your package root with this exemplary content:
module.exports = function (config) {
    config.set({
        frameworks: ["mocha", "karma-typescript"],
        files: [{
            pattern: "src/**/*.ts"
        }, {
            pattern: "tests/**/*.ts"
        }],
        preprocessors: {
            "**/*.ts": ["karma-typescript"]
        },
        reporters: ["dots", "karma-typescript"],
        browsers: ["jsdom"],
        karmaTypescriptConfig: {
            reports: {
                "text-summary": ""
            },
            compilerOptions: {
                "lib": [
                    "es2015",
                    "dom"
                ],
                "baseUrl": ".",
                "paths": {
                    "YOUR_PACKAGE_NAME": [
                        "./src/index.ts"
                    ]
                }
            }
        }
    });
};
  • call npm test, happy testing!