一饮而尽,茉莉窗口不定义的错误 [英] gulp-jasmine Window is not defined error

查看:247
本文介绍了一饮而尽,茉莉窗口不定义的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用一饮而尽/吞掉,茉莉/角度来运行我的单元测试。不过,我跑我的目标咕嘟咕嘟时遇到以下错误:

  C:\\项目\\ WEBSITE2>一饮而尽测试
[1点53分10秒]使用gulpfile C:\\项目\\ WEBSITE2 \\ gulpfile.js
[1点53分10秒]启动测试...
[一时53分11秒]版本:1.4.13的WebPack
         资产大小的块块名称
test.bundle.js 1051728 0 [发出]测试
F失败:
1)异常负荷:C:\\项目\\ WEBSITE2 \\脚本\\ DIST \\ test.bundle.js错误
1.1)的ReferenceError:未定义窗口1规格,1失败
完成了0.015秒
[一时53分11秒]测试后916毫秒出错
[一时53分11秒]于插件错误吞掉-茉莉花
信息:
    测试失败

我相信一饮而尽,茉莉使用PhantomJS(没有浏览器窗口触发)。有人可以帮我,我做错了什么?是否有一个配置设置我失踪?

下面是我的gulpfile.js:

  VAR一饮而尽=要求('吞掉');
VAR路径=要求('路径');
VAR的WebPack =要求('一饮而尽-的WebPack');
VAR webpackConfig =要求('./ webpack.config');
VAR testWebpackConfig =要求('./ test.webpack.config');
VAR茉莉=要求('一饮而尽-茉莉');gulp.task('默认',['打造'],函数(){});gulp.task('打造',函数(){
    返回gulp.src(['脚本/应用/ ** / *。JS','!脚本/应用/ ** / *。tests.js'])
       .pipe(的WebPack(webpackConfig))
       .pipe(gulp.dest('脚本/ DIST'));
});gulp.task(测试,函数(){
    返回gulp.src(['脚本/应用/ ** / *。tests.js'])
       .pipe(的WebPack(testWebpackConfig))
       .pipe(gulp.dest('脚本/ DIST'))
       .pipe(茉莉());
});


解决方案

吞掉,茉莉贯穿Node.js的测试,因此不适合于客户端测试,看的 https://github.com/sindresorhus/gulp-jasmine/issues/46

有关客户端的测试,如果你想用茉莉花(而不是因果报应或并联),你可以写一个SpecRunner.html文件(名称并不重要),并在浏览器中运行它:

 <!DOCTYPE HTML>
< HTML和GT;
  < HEAD>
    <间的charset =UTF-8>
    <标题>茉莉规格亚军< /标题>    <! - 你需要在你的Node.js的package.json指定包茉莉花核心 - >    <链接rel =快捷方式图标的href =node_modules /茉莉核心/图像/ jasmine_favicon.png>
    <链接rel =stylesheet属性HREF =node_modules /茉莉核心/ lib目录/茉莉核心/ jasmine.css>    <脚本SRC =node_modules /茉莉核心/ lib目录/茉莉核心/ jasmine.js>< / SCRIPT>
    <脚本SRC =node_modules /茉莉核心/ lib目录/茉莉核心/茉莉html.js>< / SCRIPT>
    <脚本SRC =node_modules /茉莉核心/ lib目录/茉莉核心/ boot.js>< / SCRIPT>    <! - 来源和规格的依赖 - >
    <脚本SRC =node_modules /下划线/ underscore.js>< / SCRIPT>
    &所述; SCRIPT SRC =node_modules /角度/ angular.js>&下; /脚本>
    &所述; SCRIPT SRC =node_modules /角嘲笑/角mocks.js>&下; /脚本>    <! - 源文件 - >
    <脚本SRC =应用程序/ MYSOURCE code1.js>< / SCRIPT>
    <脚本SRC =应用程序/ MYSOURCE code2.js>< / SCRIPT>    <! - 规格文件 - >
    <脚本SRC =测试/ MYSOURCE code1.spec.js>< / SCRIPT>
    <脚本SRC =测试/ MYSOURCE code2.spec.js>< / SCRIPT>
  < /头>
  <身体GT;
  < /身体GT;
< / HTML>

或者使用吞掉,茉莉的浏览器

  VAR一饮而尽=要求('吞掉');
变量$ =要求('一饮而尽负载-插件')();//你需要指定包茉莉花核心和吞掉-茉莉浏览器
//你的Node.js的package.jsongulp.task('茉莉',函数(){
  返回gulp.src([
    node_modules /下划线/ underscore.js',
    node_modules /角/ angular.js',
    node_modules /角嘲笑/角mocks.js',    应用程序/ MYSOURCE code1.js',
    应用程序/ MYSOURCE code2.js',
    测试/ MYSOURCE code1.spec.js',
    测试/ MYSOURCE code2.spec.js',
  ])
    .pipe($。jasmineBrowser.specRunner())
    .pipe($ jasmineBrowser.server());
});

或者使用:)

I am using gulp / gulp-jasmine / angular to run my unit tests. However, I encounter the following error when running my Gulp target:

C:\Projects\website2>gulp test
[01:53:10] Using gulpfile C:\Projects\website2\gulpfile.js
[01:53:10] Starting 'test'...
[01:53:11] Version: webpack 1.4.13
         Asset     Size  Chunks             Chunk Names
test.bundle.js  1051728       0  [emitted]  test
F

Failures:
1) Exception loading: C:\Projects\website2\scripts\dist\test.bundle.js Error
1.1) ReferenceError: window is not defined

1 spec, 1 failure
Finished in 0.015 seconds
[01:53:11] 'test' errored after 916 ms
[01:53:11] Error in plugin 'gulp-jasmine'
Message:
    Tests failed

I believe gulp-jasmine uses PhantomJS (no browser window is triggered). Can someone help me with what I'm doing wrong? Is there a configuration setting I'm missing?

Here is my gulpfile.js:

var gulp = require('gulp');
var path = require('path');
var webpack = require('gulp-webpack');
var webpackConfig = require('./webpack.config');
var testWebpackConfig = require('./test.webpack.config');
var jasmine = require('gulp-jasmine');

gulp.task('default', ['build'], function() {

});

gulp.task('build', function() {
    return gulp.src(['scripts/app/**/*.js', '!scripts/app/**/*.tests.js'])
       .pipe(webpack(webpackConfig))
       .pipe(gulp.dest('scripts/dist'));
});

gulp.task('test', function() {
    return gulp.src(['scripts/app/**/*.tests.js'])
       .pipe(webpack(testWebpackConfig))
       .pipe(gulp.dest('scripts/dist'))       
       .pipe(jasmine());
});

解决方案

gulp-jasmine runs the tests through Node.js and thus is not suitable for client side testing, see https://github.com/sindresorhus/gulp-jasmine/issues/46

For client side tests, if you want to use Jasmine (instead of Karma or in parallel), you can write a SpecRunner.html file (the name does not matter) and run it in your browser:

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>Jasmine Spec Runner</title>

    <!-- You need to specify package 'jasmine-core' in your Node.js package.json -->

    <link rel="shortcut icon" href="node_modules/jasmine-core/images/jasmine_favicon.png">
    <link rel="stylesheet" href="node_modules/jasmine-core/lib/jasmine-core/jasmine.css">

    <script src="node_modules/jasmine-core/lib/jasmine-core/jasmine.js"></script>
    <script src="node_modules/jasmine-core/lib/jasmine-core/jasmine-html.js"></script>
    <script src="node_modules/jasmine-core/lib/jasmine-core/boot.js"></script>

    <!-- Source and Spec dependencies -->
    <script src="node_modules/underscore/underscore.js"></script>
    <script src="node_modules/angular/angular.js"></script>
    <script src="node_modules/angular-mocks/angular-mocks.js"></script>

    <!-- Source files -->
    <script src="app/MySourceCode1.js"></script>
    <script src="app/MySourceCode2.js"></script>

    <!-- Spec files -->
    <script src="test/MySourceCode1.spec.js"></script>
    <script src="test/MySourceCode2.spec.js"></script>
  </head>
  <body>
  </body>
</html>

Or use gulp-jasmine-browser:

var gulp = require('gulp');
var $ = require('gulp-load-plugins')();

// You need to specify packages 'jasmine-core' and 'gulp-jasmine-browser'
// in your Node.js package.json

gulp.task('jasmine', function() {
  return gulp.src([
    'node_modules/underscore/underscore.js',
    'node_modules/angular/angular.js',
    'node_modules/angular-mocks/angular-mocks.js',

    'app/MySourceCode1.js',
    'app/MySourceCode2.js',
    'test/MySourceCode1.spec.js',
    'test/MySourceCode2.spec.js',
  ])
    .pipe($.jasmineBrowser.specRunner())
    .pipe($.jasmineBrowser.server());
});

Or use Karma :)

这篇关于一饮而尽,茉莉窗口不定义的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆