Comments (3)
Hey @asmagin and @stephan-nordnes-eriksen – thanks for opening an issue!
The testing infrastructure is significantly simplified in the latest release, and there are now lots of examples of both internal and public APIs being tested. Please take a look and let me know what you think.
I'm going to close this issue now, but please let me know if I should re-open.
from typescript-starter.
I am having the same problem. I believe the root cause is that the test files are being move to a test folder. I am looking into perhaps updating the build-tests.js
to see if I can get the require-paths to match what they should be.
I believe the other alternative is to move your tests into a more standard layout for typescript (separate folder for tests)
from typescript-starter.
I am not sure this is the ideal solution, but it is at least "a solution";
Change the content of the build-tests.js with the following;
// this script watches the tests exported by typescript, copies them to the test directories, and modifies the require("PKG.NAME") statements to test each build
const cpx = require("cpx");
const separator = require("path").sep;
const Transform = require("stream").Transform;
const pkg = require('../../package');
const req = (path) => 'require("' + path + '")';
const pathUp = (levels) => Array.from(Array(levels), () => '../').join('');
// replace instances of pkg.name with the proper route to the build being tested
const makeTransform = (filePath, buildPath) => {
const buildPathParts = buildPath.split(separator);
const filePathParts = filePath.split(separator);
// filePath includes build/main (-2), test/BUILD is 2 deep (+2),
// remove filename (-1). Total is length - 2
const pathToRoot = pathUp(filePath.split(separator).length - 1);
const placeholder = req(pkg.name);
return new Transform({
transform(chunk, encoding, done) {
const str = chunk.toString();
const parts = str.split(placeholder)
const newPath = req(pathToRoot + buildPath)
const result = parts.join(newPath)
.replace(/require\(\"\.\.\//g, 'require("' + pathToRoot + filePathParts.slice(0, -2).join(separator) + separator)
.replace(/require\(\"\.\//g, 'require("' + pathToRoot + filePathParts.slice(0, -1).join(separator) + separator);
this.push(result);
done();
}
});
}
// copy, then watch for changes to the tests
const testsFromRoot = 'build/main/**/*.spec.js';
const watchMode = process.argv.indexOf('-w') !== -1 ? true : false;
const browserTests = process.argv.indexOf('--no-browser') !== -1 ? true : false;
const task = watchMode ? cpx.watch : cpx.copy;
task(testsFromRoot, 'test/main', {
transform: (filePath) => makeTransform(filePath, pkg.main)
});
if (!browserTests) {
task(testsFromRoot, 'test/browser', {
transform: (filePath) => makeTransform(filePath, pkg.browser.replace('.js', '.cjs.js'))
});
}
from typescript-starter.
Related Issues (20)
- How can I set up express server typescript-starter HOT 1
- An in-range update of codecov is breaking the build 🚨 HOT 4
- Project Status HOT 6
- node_modules/ava/index.d.ts:5:10 - error TS2339: Property 'observable' does not exist on type 'SymbolConstructor'. HOT 4
- Can't generate docs with circular type HOT 1
- AppVeyor breaks on Node.js v14 HOT 1
- Add support for a GitHub Actions test matrix
- Cannot find namespace 'WebAssembly' HOT 2
- error TS2307: Cannot find module './lib/hash' or its corresponding type declarations. HOT 1
- Cannot find types for node error when running `npm run watch:build` HOT 2
- error TS2688: Cannot find type definition file for 'node'. HOT 4
- How do I generate a nodejs application with this starter? HOT 2
- Why there is a dependency of @bitauth/libauth? HOT 2
- Unexpected end of JSON input Error HOT 1
- Peer dependency mismatch causes project creation to be broken
- The javascript module link redirects to "Laptoptalks..."
- Option to work with ESM (ES Module) only libraries like node-fetch
- `pnpm` support as package manager HOT 4
- @bitauth/libauth dependency in generated project
- New project has errors in node_modules HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from typescript-starter.