Skip to content

Can't set test directory outside of folder where test.ts is located in -beta.19 #3077

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
harunurhan opened this issue Nov 9, 2016 · 14 comments
Labels
P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent type: bug/fix

Comments

@harunurhan
Copy link

OS?

macOS Sierra

Versions.

angular-cli: 1.0.0-beta.19-3
node: 5.12.0
os: darwin x64

Repro steps.

in generated test.ts, I only changed the test files path require.context('../other-folder', true, /\.spec\.ts/);. It was working in beta.15 but with beta.19 I get
ERROR in ENOTDIR: not a directory, scandir '/path/to/other-folder/index.ts', just before karma is started, in other words before [karma]: Karma v1.2.0 server started at http://localhost:9876/ log. And for this reason it doesn't find any test, prints Chrome 54.0.2840 (Mac OS X 10.12.1): Executed 0 of 0 ERROR (0.004 secs / 0 secs).

Same setup works when I use ./ path but my tests are in another folder.

The log given by the failure.

ERROR in ENOTDIR: not a directory, scandir '/path/to/other-folder/index.ts'

there is no stack trace or more log messages even if when I start karma with verbose flag.

@valorkin
Copy link
Contributor

valorkin commented Nov 9, 2016

I have same issue, but reproduce steps a bit easier:

  • create new app (ng create ...)
  • rename src/main.ts to src/index.ts (update angular-cli.json accordingly)
  • run ng test

and ERROR in ENOTDIR: not a directory, scandir '/path/to/other-folder/index.ts' appears

@BernhardRode
Copy link

Same issue..

i'm using the /src/index.ts to be able to import my stuff from another repo.

@valorkin
Copy link
Contributor

status update: issue is related to .then(() => require.context('./', true, /\.spec\.ts/))
pointing require.context to any folder with index.ts produces an issue
digging deeper...

@valorkin
Copy link
Contributor

valorkin commented Nov 16, 2016

@hansl do you have an idea where in require.context chain
./src could be replaced with ./src/index.ts if index.ts file exists
which leads later to fs.readdir('./src/index.ts') and this one leads to mentioned exception

@valorkin
Copy link
Contributor

@hansl @Brocco may I bring your attention to this issue?
it is a bit of blocker if you are using index.ts files

@filipesilva
Copy link
Contributor

This might have been a side effect of https://github.com/angular/angular-cli/pull/2291/files. Can you try locally deleting modules: [path.resolve(projectRoot, 'node_modules')] to see if that fixes it?

@filipesilva filipesilva added command: test P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent type: bug/fix labels Nov 22, 2016
@valorkin
Copy link
Contributor

@filipesilva I will try to

@bfwg
Copy link

bfwg commented Dec 22, 2016

Same error.
angular-cli: 1.0.0-beta.21
node: 6.9.2
os: darwin x64
I'm building an lib project using CLI and I want to run tests in my lib folder instead of the demo app folder.

@charpeni
Copy link
Contributor

charpeni commented Jan 6, 2017

@filipesilva @valorkin Unfortunately, that does not solve this issue, require.context still resolve inner index.ts instead of folder.

@harunurhan
Copy link
Author

harunurhan commented Jan 11, 2017

@bfwg I am trying to do same, but now had to pin to the version, however I need the latest for some new fixes.

any plan to fix this soon? @filipesilva @hansl

@harunurhan
Copy link
Author

harunurhan commented Feb 3, 2017

I upgraded angular-cli to 1.0.0-beta.28.3lately, and now it works for me.

@Brocco
Copy link
Contributor

Brocco commented Feb 3, 2017

@harunurhan that's great to hear!!!

Closing this issue as it is reported to be working now.

@Brocco Brocco closed this as completed Feb 3, 2017
@hanvyj
Copy link

hanvyj commented Oct 11, 2017

I'm having this issue in 1.4.5. Replacing:

    const context = require.context('./', true, /\.spec\.ts$/);

with:

    const context = require.context('../server', true, /\.spec\.ts$/);

fails to find any tests. I can manually add files using absolute path:

    const context = require.context('c:/Projects/project/server/models', true, /\.spec\.ts$/);

But it doesn't seem to be combining relative paths correctly, as using:

    context.push(require.resolve('../server/models/client.spec'));

I'm getting the error:

ERROR in ./src/test.ts
Module not found: Error: Can't resolve '../server/models/client.spec' in 'C:\Projects\project\src'
 @ ./src/test.ts 19:13-60

@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 7, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent type: bug/fix
Projects
None yet
Development

No branches or pull requests

8 participants