Skip to content
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

Can not run unit tests through jest framework because of SyntaxError: Unexpected token export #66

Closed
sharikovvladislav opened this issue Aug 20, 2017 · 37 comments

Comments

@sharikovvladislav
Copy link
Contributor

Hi!

I have this problem:

sharikovvlad:ng2-diary-book svlad$ npm run jest -- --debug

> angular-ngrx-diary@0.0.0 jest /Users/svlad/dev/ng2-diary-book
> jest "--debug"

{
  "config": {
    "automock": false,
    "browser": false,
    "cache": true,
    "cacheDirectory": "/var/folders/pf/510z0sc56zq3hvfb7lyr0jlr0000gn/T/jest_dx",
    "clearMocks": false,
    "coveragePathIgnorePatterns": [
      "/node_modules/"
    ],
    "globals": {
      "ts-jest": {
        "tsConfigFile": "src/tsconfig.spec.json"
      },
      "__TRANSFORM_HTML__": true
    },
    "haste": {
      "providesModuleNodeModules": []
    },
    "moduleDirectories": [
      "node_modules"
    ],
    "moduleFileExtensions": [
      "ts",
      "js",
      "html",
      "json"
    ],
    "moduleNameMapper": [
      [
        "(.*)",
        "/Users/svlad/dev/ng2-diary-book/src/$1"
      ]
    ],
    "modulePathIgnorePatterns": [],
    "name": "520410dc90eed72792e9fd01593c2a6d",
    "resetMocks": false,
    "resetModules": false,
    "rootDir": "/Users/svlad/dev/ng2-diary-book",
    "roots": [
      "/Users/svlad/dev/ng2-diary-book"
    ],
    "setupFiles": [],
    "setupTestFrameworkScriptFile": "/Users/svlad/dev/ng2-diary-book/src/setupJest.ts",
    "snapshotSerializers": [],
    "testEnvironment": "jest-environment-jsdom",
    "testMatch": [],
    "testPathIgnorePatterns": [
      "/node_modules/"
    ],
    "testRegex": "(/__tests__/.*|\\.(test|spec))\\.(ts|js)$",
    "testRunner": "/Users/svlad/dev/ng2-diary-book/node_modules/jest-jasmine2/build/index.js",
    "testURL": "about:blank",
    "timers": "real",
    "transform": [
      [
        "^.+\\.(ts|js|html)$",
        "/Users/svlad/dev/ng2-diary-book/node_modules/jest-preset-angular/preprocessor.js"
      ]
    ],
    "transformIgnorePatterns": [
      "/Users/svlad/dev/ng2-diary-book/node_modules/(?!@ngrx|angularfire2)"
    ]
  },
  "framework": "jasmine2",
  "globalConfig": {
    "bail": false,
    "coverageReporters": [
      "json",
      "text",
      "lcov",
      "clover"
    ],
    "expand": false,
    "mapCoverage": true,
    "noStackTrace": false,
    "notify": false,
    "projects": [
      "/Users/svlad/dev/ng2-diary-book"
    ],
    "rootDir": "/Users/svlad/dev/ng2-diary-book",
    "testPathPattern": "",
    "testResultsProcessor": null,
    "updateSnapshot": "new",
    "useStderr": false,
    "verbose": null,
    "watch": false,
    "watchman": true
  },
  "version": "20.0.4"
}
 PASS  src/app/diary/components/diary.spec.ts
 FAIL  src/app/diary/containers/my-dairy-page.spec.ts
  ● Test suite failed to run

    /Users/svlad/dev/ng2-diary-book/node_modules/angularfire2/auth.js:1
    ({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){export * from './auth/auth';
                                                                                             ^^^^^^

    SyntaxError: Unexpected token export

      at ScriptTransformer._transformAndBuildScript (node_modules/jest-runtime/build/ScriptTransformer.js:289:17)
      at Object.<anonymous> (src/app/core/containers/app.ts:18:14)
      at Object.<anonymous> (src/app/core/core.module.ts:15:13)

Test Suites: 1 failed, 1 passed, 2 total
Tests:       1 passed, 1 total
Snapshots:   0 total
Time:        2.709s
Ran all test suites.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! angular-ngrx-diary@0.0.0 jest: `jest "--debug"`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the angular-ngrx-diary@0.0.0 jest script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/svlad/.npm/_logs/2017-08-20T21_09_30_035Z-debug.log
sharikovvlad:ng2-diary-book svlad$

You can see what how I set up jest here: https://github.com/sharikovvladislav/ng2-diary-book/tree/feature/try-add-jest

Also, I debugged a bit and realised that angularfire2 deploy their lib without transpiling, so I have to do it by myself. Thats why I added this to the initial config you suggest:

    "transformIgnorePatterns": [
      "<rootDir>/node_modules/(?!@ngrx|angularfire2)"
    ]

Repro:

  1. Clone my repo https://github.com/sharikovvladislav/ng2-diary-book and checkout branch try-add-jest
  2. Run yarn install
  3. Run npm run jest
  4. Here is the problem.

I also described everything there https://stackoverflow.com/questions/45786951/why-i-got-syntax-error-on-jest-run-when-transpiling-is-on and there angular/angularfire#1118

I also tried to set empty array to transformIgnorePatterns and I still get same error. Tests are running for centuries so jest (babel) is trying to transpile whole project (including node_modules), but I still get same problem.

Can you please help me?

@sharikovvladislav sharikovvladislav changed the title Can not unit tests through jest because of Syntax error (export token) Can not unit tests through jest because of SyntaxError: Unexpected token export Aug 20, 2017
@sharikovvladislav sharikovvladislav changed the title Can not unit tests through jest because of SyntaxError: Unexpected token export Can not run unit tests through jest framework because of SyntaxError: Unexpected token export Aug 20, 2017
@sharikovvladislav
Copy link
Contributor Author

This issue must be related to #64

@thymikee
Copy link
Owner

Do you have a tsconfig for specs? Because you need TS to transpile ES6 modules to commonjs: like here:

@sharikovvladislav
Copy link
Contributor Author

sharikovvladislav commented Aug 21, 2017

Yes I have. Here is it.

I have generated Angular app (generated via @angular/cli@1.3.0). So I think I have everything what you have in your Angular example

Also, as we can see from output with --debug flag path to config is correct:

// ...
    "globals": {
      "ts-jest": {
        "tsConfigFile": "src/tsconfig.spec.json"
      },
      "__TRANSFORM_HTML__": true
    },
// ...

May be <rootDir> should be added?

@sharikovvladislav
Copy link
Contributor Author

sharikovvladislav commented Aug 21, 2017

Look at my spec ts config. Note this section. I mean files and include sections. I thought it can be because of it. There are no *.js files there. But your example have same code there.

Are you sure this tsconfig influence transpiling of files?

Should I provide something else so you can understand the problem better? By the way you can easy repro this problem in a few steps.

@thymikee
Copy link
Owner

I'm going to close this, as it looks like the same issue as #64. Let's discuss it there.

@thymikee
Copy link
Owner

Hm, just checked out the repo and it seems a little different here.
Unfortunately, for a couple of following weeks I don't have enough resources to process this issue. Hopefully you'll be able to fix it. You can also seek some advice on ts-jest (maybe there's already solved issue like this)

@thymikee thymikee reopened this Aug 21, 2017
@sharikovvladislav
Copy link
Contributor Author

sharikovvladislav commented Aug 21, 2017

So do you suggest to compare all configs? I checked and everything was same... On first look.

I also tried to add .babelrc with contents:

{
  "presets": ["es2015", "es2016", "es2017", "es2018"]
}

And I added option to my config to use babelrc. Same results.

What else I can compare? We have tsconfig.json, package.json and src/tsconfig.spec.json. I noticed different libraries in tsconfig.json, I tried to add es2016/es2015 and I got same result.

@thymikee
Copy link
Owner

The preprocessor used is ts-jest/preprocessor.js. Your project doesn't use Babel.

I've investigated a bit and it's not a problem with Jest. The process function from ts-jest for some reason doesn't transform the code in from angularfire2.

return process(src, path, config, transformOptions);

That's all I can help with.

@sharikovvladislav
Copy link
Contributor Author

By the way. How you suggest to use process.stoud.write in your file:

const process = require('ts-jest/preprocessor.js').process;
const TEMPLATE_URL_REGEX = /templateUrl:\s*('|")(\.\/){0,}(.*)('|")/g;
const STYLE_URLS_REGEX = /styleUrls:\s*\[\s*((?:'|").*\s*(?:'|")).*\s*.*\]/g;
const ESCAPE_TEMPLATE_REGEX = /(\${|\`)/g;


module.exports.process = (src, path, config, transformOptions) => {
  if (path.endsWith('.html')) {
    src = src.replace(ESCAPE_TEMPLATE_REGEX, '\\$1');
  }
  src = src
    .replace(TEMPLATE_URL_REGEX, 'template: require($1./$3$4)')
    .replace(STYLE_URLS_REGEX, 'styles: []');

  console.log('jest-preset-angular preprocessor', path);
  return process(src, path, config, transformOptions);
};

You define process and it is not that global nodejs process anymore, isn`t it?

@sharikovvladislav
Copy link
Contributor Author

Looks like there is some problem with transformIgnorePatterns opt.

I tried:

    "transformIgnorePatterns": [
      "<rootDir>/node_modules/(?!@ngrx)",
      "<rootDir>/node_modules/(?!angularfire2)"
    ],

And I don't see anything from node_modules at all.

I also tried:

    "transformIgnorePatterns": [
      "<rootDir>/node_modules/(?!angularfire2)"
    ],

And now I see:

jest-preset-angular preprocessor /Users/svlad/dev/ng2-diary-book/node_modules/angularfire2/auth.js

in the output.

But result is still same :)

    ({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){export * from './auth/auth';
                                                                                             ^^^^^^
    
    SyntaxError: Unexpected token export

@sharikovvladislav
Copy link
Contributor Author

sharikovvladislav commented Aug 21, 2017

Any thoughts?

PS: console.log works from time to time.

@thymikee
Copy link
Owner

just try

if (path.includes('angularfire2') {
  throw path // or process.stdout.write(`\n\n${path}\n\n`);
}

Then you can check the output of process(...) fn – it will be the same as src

@GeeWee
Copy link

GeeWee commented Aug 21, 2017

@thymikee ts-jest does use babel internally for some things, such as synthetic default modules.
If you want to use a .babelrc file you'll have to manually toggle the switch however: https://github.com/kulshekhar/ts-jest#using-babelrc

@thymikee
Copy link
Owner

@GeeWee wasn't aware of that, thanks!

@sharikovvladislav
Copy link
Contributor Author

@GeeWee ty! I already tried to use babelrc but it is not the point. For some reasons jest-preset-angular does not even try to process specified files.

@thymikee one moment

@DorianGrey
Copy link

DorianGrey commented Aug 21, 2017

If the distributed package contains ES2015+ code, you have to preprocess it via babel - typescript (and thus ts-jest) may only tolerate it, but do not transpile it. The babel options are intended for chaining transpilation, which is required for allowSyntheticDefaultImports (at least in most cases).

Here is an example how to set this up properly...

  • Adopt Jest options to be like:
 "transform": {
    "^.+\\.(ts|html)$": "<rootDir>/node_modules/jest-preset-angular/preprocessor.js",
    "^.+\\.js$": "babel-jest"
  },
  "transformIgnorePatterns": ["node_modules/(?!(@ngrx|angularfire2))"]
  • Add a .babelrc like:
{
  "presets": ["env"]
}

(Preset can be installed via yarn add --dev babel-preset-env).

@sharikovvladislav
Copy link
Contributor Author

sharikovvladislav commented Aug 21, 2017

@thymikee I tried this:

  const result = process(src, path, config, transformOptions);

  if (path.includes('angularfire')) {
    throw path + result;
  }

  return result;

I have no throws :)

I am trying with:

    "transformIgnorePatterns": [
      "<rootDir>/node_modules/(?!angularfire2)"
    ]

@sharikovvladislav
Copy link
Contributor Author

sharikovvladislav commented Aug 21, 2017

After @DorianGrey comment I have this jest config:

 "jest": {
    "preset": "jest-preset-angular",
    "setupTestFrameworkScriptFile": "<rootDir>/src/setupJest.ts",
    "transform": {
      "^.+\\.(ts|html)$": "<rootDir>/node_modules/jest-preset-angular/preprocessor.js",
      "^.+\\.js$": "babel-jest"
    },
    "transformIgnorePatterns": ["node_modules/(?!(@ngrx|angularfire2|firebase))"],
    "globals": {
      "ts-jest": {
        "tsConfigFile": "src/tsconfig.spec.json",
        "useBabelrc": true
      },
      "__TRANSFORM_HTML__": true
    }
  },

and this .babelrc:

{
  "presets": ["env"]
}

And I stopped getting error about angularfire2. Looks like now everything is ok with it.

I got another error:

 FAIL  src/app/diary/containers/my-dairy-page.spec.ts
  ● Test suite failed to run

    TypeError: Object prototype may only be an Object or null: undefined
        at setPrototypeOf (<anonymous>)
      
      at Object.<anonymous>.__extends (node_modules/firebase/database/core/snap/indexes/KeyIndex.js:44:9)
      at node_modules/firebase/database/core/snap/indexes/KeyIndex.js:54:5
      at Object.<anonymous> (node_modules/firebase/database/core/snap/indexes/KeyIndex.js:119:2)
      at Object.<anonymous> (node_modules/firebase/database/api/Query.js:31:17)
      at Object.<anonymous> (node_modules/firebase/database/api/Reference.js:20:14)
      at Object.<anonymous> (node_modules/firebase/database/api/Database.js:20:18)
      at Object.<anonymous> (node_modules/firebase/database.js:39:17)
      at Object.<anonymous> (node_modules/angularfire2/database/database.js:1:205)
      at Object.<anonymous> (node_modules/angularfire2/database.js:1:181)
      at Object.<anonymous> (src/app/diary/services/diary-entry.ts:24:18)
      at Object.<anonymous> (src/app/diary/containers/my-dairy-page.spec.ts:21:21)
          at <anonymous>

I don't get this in runtime.

@sharikovvladislav
Copy link
Contributor Author

sharikovvladislav commented Aug 21, 2017

Probably I get my last error not because of problems with jest-preset-angular. But why I didn't get that error in jasmine?

You can see last result there: https://circleci.com/gh/sharikovvladislav/ng2-diary-book/98. By the way: I don't know why but result on CI and on my Mac differs. I have another error. Argh!

Perhaps I should debug this problem too. I need to understand why in Chrome I don't get error, but jest shows this error. Lets pause this issue for some time. @thymikee

@DorianGrey
Copy link

DorianGrey commented Aug 21, 2017

Not sure why you get this - it's not a jest-preset-angular problem, nor a ts-jest one.
(Besides: There is no need to put firebase to the ignore exception list - it's valid ES5).

If I try to execute your tests with the setup above, it raises an error like this, which is related to jsdom:

yarn jest v0.27.5
$ jest
 PASS  src/app/diary/components/diary.spec.ts
 FAIL  src/app/diary/containers/my-dairy-page.spec.ts (6.528s)
  ● Console

    console.warn node_modules/zone.js/dist/zone-node.js:391
      Current document does not have a doctype. This may cause some Angular Material components not to behave as expected.
    console.warn node_modules/zone.js/dist/zone-node.js:391
      Could not find Angular Material core theme. Most Material components may not work as expected. For more info refer to the theming guide: https://material.angular.io/guide/theming
    console.warn node_modules/zone.js/dist/zone-node.js:391
      Could not find HammerJS. Certain Angular Material components may not work correctly.

  ● MyDairyPageComponent › should create

    ReferenceError: CSS is not defined
      
      at new Platform (node_modules/@angular/src/cdk/platform/platform.ts:29:1)
      at _createClass (packages/core/src/view/ng_module.ts:146:1)
      at _createProviderInstance$1 (packages/core/src/view/ng_module.ts:121:1)
      at resolveNgModuleDep (node_modules/@angular/core/bundles/core.umd.js:9504:17)

See the related discussion: #52

@sharikovvladislav
Copy link
Contributor Author

@DorianGrey hm, I have same on CI: ReferenceError: CSS is not defined. Let me check locally again.

I got another error:

    TypeError: Object prototype may only be an Object or null: undefined
        at setPrototypeOf (<anonymous>)
      
      at Object.<anonymous>.__extends (node_modules/firebase/database/core/snap/indexes/KeyIndex.js:44:9)
      at node_modules/firebase/database/core/snap/indexes/KeyIndex.js:54:5
      at Object.<anonymous> (node_modules/firebase/database/core/snap/indexes/KeyIndex.js:119:2)
      at Object.<anonymous> (node_modules/firebase/database/api/Query.js:31:17)
      at Object.<anonymous> (node_modules/firebase/database/api/Reference.js:20:14)
      at Object.<anonymous> (node_modules/firebase/database/api/Database.js:20:18)
      at Object.<anonymous> (node_modules/firebase/database.js:39:17)
      at Object.<anonymous> (node_modules/angularfire2/database/database.js:1:205)
      at Object.<anonymous> (node_modules/angularfire2/database.js:1:181)
      at Object.<anonymous> (src/app/diary/services/diary-entry.ts:24:18)
      at Object.<anonymous> (src/app/diary/containers/my-dairy-page.spec.ts:21:21)
          at <anonymous>

I will check again.

@DorianGrey
Copy link

DorianGrey commented Aug 21, 2017

@sharikovvladislav,

it seems that window.CSS is not yet supported in jsdom. A workaround for this error would be to define it in setupJest.ts, like:

Object.defineProperty(window, "CSS", {
  value: {
    supports() {
      return false;
    },
    escape(input) {
      return input;
    }
  }
});

(API docs: https://developer.mozilla.org/en-US/docs/Web/API/CSS)

Test execution afterwards:

yarn jest v0.27.5
$ jest
 PASS  src/app/diary/components/diary.spec.ts
 PASS  src/app/diary/containers/my-dairy-page.spec.ts (5.261s)
  ● Console

    console.warn node_modules/zone.js/dist/zone-node.js:391
      Current document does not have a doctype. This may cause some Angular Material components not to behave as expected.
    console.warn node_modules/zone.js/dist/zone-node.js:391
      Could not find Angular Material core theme. Most Material components may not work as expected. For more info refer to the theming guide: https://material.angular.io/guide/theming
    console.warn node_modules/zone.js/dist/zone-node.js:391
      Could not find HammerJS. Certain Angular Material components may not work correctly.


Test Suites: 2 passed, 2 total
Tests:       3 passed, 3 total
Snapshots:   1 passed, 1 total
Time:        6.242s, estimated 14s
Ran all test suites.
Done in 7.03s.

@sharikovvladislav
Copy link
Contributor Author

sharikovvladislav commented Aug 21, 2017

@DorianGrey can you please pull changes and try again? I pushed last changes to the repo. I pushed global mocks and your mock too.

All of that changes are available there in the PR sharikovvladislav/ng2-diary-book#41

I still get same error O_O:

sharikovvlad:ng2-diary-book svlad$ yarn jest
yarn jest v0.27.5
$ jest
 PASS  src/app/diary/components/diary.spec.ts
 FAIL  src/app/diary/containers/my-dairy-page.spec.ts
  ● Test suite failed to run

    TypeError: Object prototype may only be an Object or null: undefined
        at setPrototypeOf (<anonymous>)
      
      at Object.<anonymous>.__extends (node_modules/firebase/database/core/snap/indexes/KeyIndex.js:44:9)
      at node_modules/firebase/database/core/snap/indexes/KeyIndex.js:54:5
      at Object.<anonymous> (node_modules/firebase/database/core/snap/indexes/KeyIndex.js:119:2)
      at Object.<anonymous> (node_modules/firebase/database/api/Query.js:31:17)
      at Object.<anonymous> (node_modules/firebase/database/api/Reference.js:20:14)
      at Object.<anonymous> (node_modules/firebase/database/api/Database.js:20:18)
      at Object.<anonymous> (node_modules/firebase/database.js:39:17)
      at Object.<anonymous> (node_modules/angularfire2/database/database.js:1:205)
      at Object.<anonymous> (node_modules/angularfire2/database.js:1:181)
      at Object.<anonymous> (src/app/diary/services/diary-entry.ts:24:18)
      at Object.<anonymous> (src/app/diary/containers/my-dairy-page.spec.ts:21:21)
          at <anonymous>

Test Suites: 1 failed, 1 passed, 2 total
Tests:       2 passed, 2 total
Snapshots:   1 passed, 1 total
Time:        3.16s
Ran all test suites.
error Command failed with exit code 1.
sharikovvlad:ng2-diary-book svlad$ 

But look at the CI build: https://circleci.com/gh/sharikovvladislav/ng2-diary-book/99 . It works!!!

Eeeehm. Any ideas why I get different result relative CI and you?

I removed node_modules and run yarn install several times :(

@sharikovvladislav
Copy link
Contributor Author

sharikovvladislav commented Aug 21, 2017

Can you also show yarn list | grep firebase command output? my project should be working directory. You should get 4.2.0 since I have locked dependency tree.

@DorianGrey
Copy link

Here you are:

 yarn list | grep firebase
├─ firebase@4.2.0

However, this error is not related to firebase, directly. It is raised from an __extends helper in the KeyIndex.js mentioned in the message. And it is quite confusing:
__extends(KeyIndex, _super);leads to Object.setPrototypeOf(KeyIndex, _super), which should always be valid.

Have you tried to wipe out you local jest cache? (See https://facebook.github.io/jest/docs/troubleshooting.html#caching-issues)

@sharikovvladislav
Copy link
Contributor Author

sharikovvladislav commented Aug 21, 2017

Did you get green tests after pulling my changes? I still have same.

Ye firebase is same. Why you think that the problem is not related to firebase? I think so because of callstack: node_modules/firebase/database/core/snap/indexes/KeyIndex.js:44:9.

I didn't not know about jest cache. Thank you. Here is execution with --no-cache flag:

sharikovvlad:ng2-diary-book svlad$ yarn jest --no-cache
yarn jest v0.27.5
$ jest
 PASS  src/app/diary/components/diary.spec.ts

 RUNS  src/app/diary/containers/my-dairy-page.spec.ts
^C
sharikovvlad:ng2-diary-book svlad$ yarn jest -- --no-cache   
yarn jest v0.27.5
$ jest "--no-cache"
 PASS  src/app/diary/components/diary.spec.ts
 FAIL  src/app/diary/containers/my-dairy-page.spec.ts
  ● Test suite failed to run

    TypeError: Object prototype may only be an Object or null: undefined
        at setPrototypeOf (<anonymous>)
      
      at Object.<anonymous>.__extends (node_modules/firebase/database/core/snap/indexes/KeyIndex.js:44:9)
      at node_modules/firebase/database/core/snap/indexes/KeyIndex.js:54:5
      at Object.<anonymous> (node_modules/firebase/database/core/snap/indexes/KeyIndex.js:119:2)
      at Object.<anonymous> (node_modules/firebase/database/api/Query.js:31:17)
      at Object.<anonymous> (node_modules/firebase/database/api/Reference.js:20:14)
      at Object.<anonymous> (node_modules/firebase/database/api/Database.js:20:18)
      at Object.<anonymous> (node_modules/firebase/database.js:39:17)
      at Object.<anonymous> (node_modules/angularfire2/database/database.js:1:205)
      at Object.<anonymous> (node_modules/angularfire2/database.js:1:181)
      at Object.<anonymous> (src/app/diary/services/diary-entry.ts:24:18)
      at Object.<anonymous> (src/app/diary/containers/my-dairy-page.spec.ts:21:21)
      at handle (node_modules/worker-farm/lib/child/index.js:44:8)
      at process.<anonymous> (node_modules/worker-farm/lib/child/index.js:51:3)
      at emitTwo (events.js:125:13)
      at process.emit (events.js:213:7)
      at emit (internal/child_process.js:774:12)
      at _combinedTickCallback (internal/process/next_tick.js:141:11)
      at process._tickCallback (internal/process/next_tick.js:180:9)

Test Suites: 1 failed, 1 passed, 2 total
Tests:       2 passed, 2 total
Snapshots:   1 passed, 1 total
Time:        4.585s
Ran all test suites.
error Command failed with exit code 1.
sharikovvlad:ng2-diary-book svlad$ 

which should always be valid.

I checked firebase code. I don't see usage of KeyIndex exported function. By callstack: error was produced from this instruction: var _KeyIndex = require('../core/snap/indexes/KeyIndex');. Thats strange. This instruction says that exported data of ../core/snap/indexes/KeyIndex is in _KeyIndex now. There is no function call.

@DorianGrey
Copy link

Did you get green tests after pulling my changes?

Yes, same as in your CI build.

Why you think that the problem is not related to firebase?

Because the referenced line points to an __extends helper:

var __extends = undefined && undefined.__extends || function () {
    var extendStatics = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function (d, b) {
        d.__proto__ = b;
    } || function (d, b) {
        for (var p in b) {
            if (b.hasOwnProperty(p)) d[p] = b[p];
        }
    };
    return function (d, b) {
        extendStatics(d, b);
        function __() {
            this.constructor = d;
        }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
}();

The referenced line is: extendStatics(d, b);
These are generated by typescript, original source is here.
Gets called via __extends(KeyIndex, _Index.Index); (c'tor call), but that should never raise an error like this.

The only issue I've found with a similar problem was this:
angular/angularfire#1044

I'm not sure what causes the error in your case, I can only tell that it works fine on both CI and my machine, which both performed a clean checkout, build and test.

@sharikovvladislav
Copy link
Contributor Author

Ok. Lets stop debugging this. Actually I realised that service which causes the problem is not needed in that case.

I removed service connected to the firebase and everything is ok now. I don't know why me, you and my CI have different result. Thats very strange.

We solved initial problem long time ago.

@thymikee perhaps this section should be extended after this issue? https://github.com/thymikee/jest-preset-angular#unexpected-token-importexportother what do you think? I mean we can add here information about js files should be processed by babel-jest, not ts-jest. Can I submit a PR?

@thymikee
Copy link
Owner

I'd love to accept a PR with this!

@sharikovvladislav
Copy link
Contributor Author

@DorianGrey Thank you very much for your suggestion. You fully solved my problem. Also thank you for next troubleshooting. You helped a lot!

@thymikee thank you for your work with jest-preset-angular. I want to try snapshot testing. Since I solved all problems at the moment I will do it in the near future.

@sharikovvladislav
Copy link
Contributor Author

Closing this one for now.

@kidd3
Copy link

kidd3 commented Aug 22, 2017

Yes this seems be similar to my issue #64, so I will have a look over your suggested fixes and see if any of them work for me also. Thanks

@sharikovvladislav
Copy link
Contributor Author

@kidd3 did you solve your problem?

@kidd3
Copy link

kidd3 commented Aug 22, 2017

@sharikovvladislav unfortunately I haven't had time today to look at this, my project is ongoing. I will aim to try it tomorrow and feed back. Is your repo that you created updated with your fix?

@sharikovvladislav
Copy link
Contributor Author

@kidd3 I have changes which solve the problem in this PR: sharikovvladislav/ng2-diary-book#41

@kidd3
Copy link

kidd3 commented Aug 25, 2017

So I've installed babel-preset-env via npm and adding a .babelrc file containing { "presets": ["env"] }

The same error 'SyntaxError: Unexpected token import' is still occurring for me, but now with additional warning: [BABEL] Note: The code generator has deoptimised the styling of ../SL/node_modules/@angular/compiler/bundles/compiler.umd.js" as it exceeds the max of "500KB".`

My original issue is here #64 if we can continue there I would appreciate any help, thanks.

@sharikovvladislav
Copy link
Contributor Author

lets go to #64

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants