lathonez / clicker

Ionic 2 + @angular/cli Seed Project : Angular2 + Typescript + Karma + Protractor + Travis
http://lathonez.com/2018/ionic-2-unit-testing/
MIT License
430 stars 136 forks source link

Test cases failing #111

Closed geoHeil closed 8 years ago

geoHeil commented 8 years ago

Hi npm test works fine on osx, but on Ubuntu it is failing with the following error:

Requiring external module ts-node/register
TSError: ⨯ Unable to compile TypeScript
test/gulpfile.ts (1,22): Cannot find module 'path'. (2307)
test/gulpfile.ts (4,9): Cannot find name 'require'. (2304)
test/gulpfile.ts (12,9): Cannot find name 'require'. (2304)
test/gulpfile.ts (13,16): Cannot find name 'require'. (2304)
test/gulpfile.ts (14,18): Cannot find name 'require'. (2304)
test/gulpfile.ts (14,31): Cannot find name 'process'. (2304)
test/gulpfile.ts (30,25): Cannot find name 'require'. (2304)
test/gulpfile.ts (46,18): Cannot find name 'require'. (2304)
test/gulpfile.ts (57,20): Cannot find name 'require'. (2304)
test/gulpfile.ts (59,22): Cannot find name 'process'. (2304)
test/gulpfile.ts (69,20): Cannot find name 'require'. (2304)
test/gulpfile.ts (71,22): Cannot find name 'process'. (2304)
test/gulpfile.ts (82,21): Cannot find name 'require'. (2304)
    at getOutput (/clicker/node_modules/ts-node/src/index.ts:280:15)
    at compile (/clicker/node_modules/ts-node/src/index.ts:289:14)
    at loader (/clicker/node_modules/ts-node/src/index.ts:304:23)
    at Object.require.extensions.(anonymous function) [as .ts] (/clicker/node_modules/ts-node/src/index.ts:321:14)
    at Module.load (module.js:343:32)
    at Function.Module._load (module.js:300:12)
    at Module.require (module.js:353:17)
    at require (internal/module.js:12:17)
    at Liftoff.handleArguments (/clicker/node_modules/gulp/bin/gulp.js:116:3)
    at Liftoff.<anonymous> (/clicker/node_modules/gulp/node_modules/liftoff/index.js:193:16)

Here is a dockerfile https://gist.github.com/geoHeil/48cd94bf4d748fd8fd6d25de4c272157 which demonstrates a linux environment which leads to this error.

lathonez commented 8 years ago

@geoHeil our CI builds are on Ubuntu 14.04 and I run arch, so it's unlikely to be a linux or ubuntu specific issue.

The above error is the typescript compiler not being able to find the node typiings:

x220:~/code/clicker$ grep node typings.json 
    "node": "registry:dt/node#6.0.0+20160514165920",

I'll have a look with the docker file you've provided later on

lathonez commented 8 years ago

replicated using the dockerfile provided

lathonez commented 8 years ago

I just had to run typings install as a separate step, so for some reason the post install hook is failing in your setup:

    "postinstall": "ionic state restore && typings install && webdriver-manager update && cp test/karma-static/*.html node_modules/karma/static",
lathonez commented 8 years ago
npm WARN cannot run in wd clicker@1.8.0 ionic state restore && typings install && webdriver-manager update && cp test/karma-static/*.html node_modules/karma/static (wd=/clicker)
lathonez commented 8 years ago

Possibly relevant:

http://stackoverflow.com/questions/18136746/npm-install-failed-with-cannot-run-in-wd

If npm was invoked with root privileges, then it will change the uid to the user account or uid specified by the user config, which defaults to nobody. Set the unsafe-perm flag to run scripts with root privileges.

Which would make sense as I presume you're running as root (I am when I replicate, and there doesn't seem to be another user on your image)

lathonez commented 8 years ago

npm install --unsafe-perms

did not work

geoHeil commented 8 years ago

Thanks a lot.

lathonez commented 8 years ago

Adding --allow-root-install to the postinstall line does the trick: EDIT: --allow-root-install doesn't actually work

The way forward seems to be just running npm run postinstall after npm install

I'm not keen to put this in the repo as default as I'm not clear on the consequences of doing so. I don't think it's good practice to run anything as root (even in docker).

I will however put something in the readme and link this issue from the blog.

geoHeil commented 8 years ago

Nope you are right. I will change the docker file.

lathonez commented 8 years ago

Sweet, closing

lathonez commented 7 years ago

191