bahmutov / bahmutov/cypress-angular-unit-test

Error importing typescript when located outside module under test in nx monorepo

Open
#292 1 comment 0 reactions 0 assignees View on GitHub
💬 need info
Dominant language
TypeScript
Stars
160
Forks
32
PR merge metrics
No merged PRs in 30d

Description

I am trying to run unit test in an angular project using nx.

When importing `ts` files which located in a different folder I an error.

This is the import statement:
```
import { Option, parseInteger } from '../../../../libs/utils/src/index';
```
Error:
```
Module parse failed: Unexpected token (18:29)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
| * If an empty list of observables is provided, this will emit []
| */
> export function flattenLatest(observables: Observable[]): Observable {
| const sources = observables.map(obs => obs.pipe(startWith([])));
| if (sources.length === 0) {
```

It appears to fail because it does not recognise it as typescript.

The following import does work:

```
import { test } from './myfunction'
```

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with the failing import from libs/utils/src/index and compare it with the working ./myfunction import. Inspect the unit-test bundling and loader setup to determine why the external TypeScript file is parsed without a TypeScript loader; done when the test imports that path successfully.

Written by the indexing model from the issue text.

Assessment

Tech stack
angular, cypress, typescript
Domain
build-system, testing
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.