Browse Source

Install karma and jasmine testing suite

Lucas de Souza 5 years ago
parent
commit
e63e6e102d
3 changed files with 1036 additions and 18 deletions
  1. 36 10
      karma.conf.js
  2. 989 6
      package-lock.json
  3. 11 2
      package.json

+ 36 - 10
karma.conf.js

@@ -1,4 +1,3 @@
-const webpackConfig = require('./webpack.config.js');
 process.env.CHROME_BIN = '/snap/bin/chromium';
  
 module.exports = function(config) {
@@ -9,7 +8,7 @@ module.exports = function(config) {
     exclude: [],
     //files/patterns to load in the browser
     files: [
-      {pattern: 'tests/*.spec.js',watched:true,served:true,included:true}
+     'tests/*.spec.js'
       /*parameters*/
           //watched: if autoWatch is true all files that have set watched to true will be watched for changes
           //served: should the files be served by Karma's webserver?
@@ -21,9 +20,9 @@ module.exports = function(config) {
     ],
     
     //executes the tests whenever one of watched files changes
-    autoWatch: true,
+    autoWatch: false,
     //if true, Karma will run tests and then exit browser
-    singleRun:false,
+    singleRun: true,
     //if true, Karma fails on running empty test-suites
     failOnEmptyTestSuite:false,
     //reduce the kind of information passed to the bash
@@ -34,7 +33,7 @@ module.exports = function(config) {
     //list of browsers to launch and capture
     browsers: ['ChromeHeadless'/*,'PhantomJS','Firefox','Edge','ChromeCanary','Opera','IE','Safari'*/],
     //list of reporters to use
-    reporters: ['mocha','kjhtml'/*,'dots','progress','spec'*/],
+    reporters: ['mocha' /*,'kjhtml','dots','progress','spec'*/],
     
     //address that the server will listen on, '0.0.0.0' is default
     listenAddress: '0.0.0.0',
@@ -47,7 +46,7 @@ module.exports = function(config) {
     //how long does Karma wait for a browser to reconnect, 2000 is default
     browserDisconnectTimeout: 5000,
     //how long will Karma wait for a message from a browser before disconnecting from it, 10000 is default
-    browserNoActivityTimeout: 10000,
+    browserNoActivityTimeout: 60000,
     //timeout for capturing a browser, 60000 is default
     captureTimeout: 60000,
  
@@ -68,22 +67,49 @@ module.exports = function(config) {
  
     /*karma-webpack config*/
     //pass your webpack configuration for karma
-    webpack: webpackConfig,
+    webpack: {
+      node: {
+        fs: 'empty',
+      },
+      module: {
+        rules: [
+            {
+              test: /\.js$/,
+              exclude: /(node_modules)/,
+              use: {
+                loader: "babel-loader",
+                options: {
+                  presets: ["@babel/preset-env"]
+                }
+              }
+            },
+            {
+              test: /\.g4$/,
+              exclude: /(node_modules)/,
+              use: {
+                loader:'antlr4-webpack-loader'
+              }
+            }
+        ]
+    },
+    },
     preprocessors: {
       //use webpack to support require() in test-suits .js files
       //use babel-loader from webpack to compile es2015 features in .js files
       //add webpack as preprocessor
-      './tests/*.js': ['webpack']
+      'tests/*.spec.js': ['webpack']
     },
     webpackMiddleware: {
       //turn off webpack bash output when run the tests
       noInfo: true,
-      stats: 'errors-only'
+      stats: {
+        chunks: false
+      }
     },
  
     /*karma-mocha-reporter config*/
     mochaReporter: {
-      output: 'noFailures'  //full, autowatch, minimal
+      output: 'full'  //full, autowatch, minimal
     }
   });
 };

File diff suppressed because it is too large
+ 989 - 6
package-lock.json


+ 11 - 2
package.json

@@ -5,8 +5,9 @@
   "main": "js/main.js",
   "scripts": {
     "start": "http-server",
-    "build": "webpack",
-    "watch": "webpack --watch"
+    "build": "webpack --mode=development",
+    "watch": "webpack --watch --mode=development",
+    "compile": "webpack --mode=production"
   },
   "repository": {
     "type": "git",
@@ -28,6 +29,14 @@
     "@babel/preset-env": "^7.3.4",
     "antlr4-webpack-loader": "^0.1.1",
     "babel-loader": "^8.0.5",
+    "html-webpack-plugin": "^3.2.0",
+    "jasmine-core": "^3.3.0",
+    "karma": "^4.0.1",
+    "karma-chrome-launcher": "^2.2.0",
+    "karma-jasmine": "^2.0.1",
+    "karma-mocha-reporter": "^2.2.5",
+    "karma-webpack": "^3.0.5",
+    "puppeteer": "^1.13.0",
     "ts-loader": "^5.2.2",
     "typescript": "^3.1.3",
     "webpack": "^4.29.0",