ReferenceError: Can't find variable: Map

后端 未结 2 1810
滥情空心
滥情空心 2020-12-20 13:57

I\'m using Angular 4, Webpack 2.4.1, Karma 1.6 and Jasmine 2.6.1 and am writing ES2015 not TypeScript

I\'ve got a tiny angular demo app and I want to

相关标签:
2条回答
  • 2020-12-20 14:16

    This is what has worked for me: I was using PhantonJs with karma and nightwatch for my testing . I was getting this error during JhantomJs initialization and as test were getting started because because there's no Map in browsers. PhantomJS is used as Karma driver, and it doesn't support ES6 features.

    I tried to load polyfills but that did not help as well. Then I saw that support for PhantonJs has long gone and felt it wont work. So I took an effort to replace PhantomJs with Chrome headless browser and surprisingly it was pretty easy to replace.

    Here are the thing I did to make the change from PhantomJs to Chrome headless:

    1. Package.json - puppeteer, chromedriver, karma-chrome-launcher as dependency
    2. Add the following in karma.conf.js
    const puppeteer = require('puppeteer');
    process.env.CHROME_BIN = puppeteer.executablePath();
    
    module.exports = function(config) {
      config.set({ 
        .
        browsers: ['ChromeHeadless'],
        .
       });
    
    
    1. Add/Edit the following in nightwatch.json
        "chrome": {
          "desiredCapabilities": {
            "browserName": "chrome",
            "javascriptEnabled": true,
            "acceptSslCerts": true,
            "chromeOptions": {
              "args": ["--no-sandbox", "headless"]
            }
          }
    

    This is something which has worked for me; may or may not work for you depending on the kind of side things you are using with JhantomJs for testing. Nevertheless should helpful for anyone who is trying to move away PhantomJs.

    0 讨论(0)
  • 2020-12-20 14:35

    This error is thrown because there's no Map in browsers. PhantomJS is used as Karma driver, and it doesn't support ES6 features.

    If polyfills (e.g. core-js) aren't loaded in files that were included in tests, they should be loaded separately, for example via karma-es6-shim plugin:

        ...
        frameworks: ['es6-shim', 'jasmine'],
        ...
    
    0 讨论(0)
提交回复
热议问题