grunt test - 致命错误:尚未实施单元测试

Posted

技术标签:

【中文标题】grunt test - 致命错误:尚未实施单元测试【英文标题】:grunt test - Fatal error: Unit testing is not implemented yet 【发布时间】:2018-10-02 01:26:28 【问题描述】:

我已经搭建好项目环境,安装grunt成功。在终端中,我尝试运行grunt,它为我显示了这个:

然后我按照步骤进行。

    grunt build --env uat(这一步运行成功) grunt watch --env uat(这一步有问题,我发了here) grunt 测试(此步骤对我显示错误:致命错误:尚未实施单元测试

这个项目包括:angularJS、jade、coffeescript,我已经搭建好了所有的环境,但是仍然不知道如何运行这个项目。

###
    Build script for ** project.

    USAGE INSTRUCTIONS:
    Run `grunt` on the command line, from the same directory as this file
    or any subfolder to see usage instructions.

    TODO:
    - Fix totally broken `--debug` mode.
    - Unit testing support.
###

module.exports = (grunt) ->

    ## Config ------------------------------------------------------------------

    Instructions = """
        Usage:
        1) Build all files once.
            grunt build --env Environment [--debug]
        2) Builds files and automatically re-build when any file changes are detected.
            grunt watch --env Environment [--debug]
        3) Builds and runs Unit Tests.
            grunt test

        Where:
        - debug: to compile for development (leave out to compile for production)
        - Environment can be the filenam (minus extension) of any environment
          file in the Environments/ directory.
    """


    ## Command Line options ----------------------------------------------------

    Debug = grunt.option("debug")?
    Env = grunt.option("env")

    if grunt.cli.tasks.length and grunt.cli.tasks[0] isnt "test"
        unless Env? and grunt.file.exists "Environments/#Env.litcoffee"
            grunt.fail.fatal "Please specify a valid environment!"
            return


    ## Helpers -----------------------------------------------------------------

    usage = ->
        grunt.log.writeln Instructions


    ## Grunt config ------------------------------------------------------------

    grunt.initConfig

        autoprefixer:
            options:
                browsers: ["last 3 versions"]
                map:
                    inline: false
            all:
                expand: true
                cwd: "Build"
                src: ["*.css"]
                dest: "Build"

        browserify:
            all:
                expand: true
                cwd: "Build/Temp/CoffeeTemp"
                src: ["*.js"]
                dest: "Build"
                ext: ".js"

        clean:
            all:
                src: ["Build"]
            temp:
                src: ["Build/Temp"]
            production: [
                "Build/**/*.js.map"
                "Build/**/*.css.map"
            ]
            stylesheets:
                src: ["Build/*.css"]
            scripts:
                src: ["Build/*.js"]
            jade:
                src: [
                    "Build/*.html"
                    "Build/templates/**/*.html"
                ]

        coffee:
            options:
                bare: true
                # sourceMap: Debug
            env:
                src: ["Environments/#Env.litcoffee"]
                dest: "Build/Temp/CoffeeTemp/services/env.js"
            all:
                expand: true
                cwd: "Source Code"
                src: ["**/*.litcoffee"]
                dest: "Build/Temp/CoffeeTemp"
                ext: ".js"

        copy:
            static:
                expand: true
                cwd: "Source Code"
                src: [ "static/**/*" ]
                dest: "Build"

        cssmin:
            options:
                sourceMap: true
            build:
                expand: true
                cwd: "Build"
                src: ["*.css"]
                dest: "Build"

        htmlmin:
            all:
                options:
                    removeComments: true
                    collapseWhitespace: true
                    conservativeCollapse: true
                files: [
                    
                        expand: true
                        cwd: "Build"
                        src: [
                            "*.html",
                            "templates/**/*.html"
                        ]
                        dest: "Build"
                        ext: ".html"
                        filter: "isFile"
                    
                ]

        jade:
            options:
                doctype: "html" # keeps attributes with no value as-is (i.e.
                    # prevents div(md-raised) from becoming
                    # <div md-raised="md-raised">...)
                data: 
                pretty: false
            all:
                files: [
                    expand: true
                    cwd: "Source Code"
                    src: [
                        "*.jade"
                        "admin/*.jade"
                        "activate/*.jade"
                        "activation/*.jade"
                        "cargoTrackingMobile/*.jade"
                        "templates/**/*.jade"
                    ]
                    dest: "Build"
                    ext: ".html"
                ]

        stylus:
            all:
                options:
                    linenos: true
                    compress: !Debug
                    sourcemap:
                        comment: true
                        inline: false
                        sourceRoot: "."
                        basePath: "."
                files: [
                    expand: true
                    cwd: "Source Code/styles"
                    src: [
                        "**/*.styl"
                        "!**/_*.styl"
                    ]
                    dest: "Build"
                    ext: ".css"
                ]

        uglify:
            options:
                mangle: 
                sourceMap: Debug
            all:
                expand: true
                cwd: "Build"
                src: ["*.js"]
                dest: "Build"

        watch_default:
            scripts:
                files: [
                    "Source Code/*.litcoffee"
                    "Source Code/**/*.litcoffee"
                    "!Source Code/static/**/*.litcoffee"
                ]
                tasks: ["scripts"]
            stylesheets:
                files: ["Source Code/styles/**/*"]
                tasks: ["stylesheets"]
            html:
                files: [
                    "Source Code/*.jade"
                    "Source Code/admin/*.jade"
                    "Source Code/activate/*.jade"
                    "Source Code/activation/*.jade"
                    "Source Code/cargoTrackingMobile/*.jade"
                    "Source Code/templates/**/*.jade"
                ]
                tasks: ["jade:all"]
            static:
                files: ["Source Code/static/**/*"]
                tasks: ["copy:static"]

    grunt.loadNpmTasks "grunt-autoprefixer"
    grunt.loadNpmTasks "grunt-browserify"
    grunt.loadNpmTasks "grunt-contrib-clean"
    grunt.loadNpmTasks "grunt-contrib-coffee"
    grunt.loadNpmTasks "grunt-contrib-copy"
    grunt.loadNpmTasks "grunt-contrib-cssmin"
    grunt.loadNpmTasks "grunt-contrib-htmlmin"
    grunt.loadNpmTasks "grunt-contrib-jade"
    grunt.loadNpmTasks "grunt-contrib-stylus"
    grunt.loadNpmTasks "grunt-contrib-uglify"
    grunt.loadNpmTasks "grunt-contrib-watch"


    ## Custom tasks ------------------------------------------------------------

    grunt.task.renameTask "watch", "watch_default"

    grunt.registerTask "default", "Usage", usage

    grunt.registerTask "scripts", "Compiles the javascript files.", [
        "clean:scripts"
        "coffee:all"
        "coffee:env"
        "browserify:all"
        "clean:temp"
    ].concat unless Debug then ["uglify:all"] else []

    grunt.registerTask "stylesheets", "Compiles the stylesheets.", [
        "clean:stylesheets"
        "stylus:all"
        "autoprefixer:all"
    ].concat unless Debug then ["cssmin"] else []

    grunt.registerTask "test", "Run unit testing.", ->
        grunt.fail.fatal "Unit testing is not implemented yet" # TODO

    grunt.registerTask "build", "Compiles all of the assets and copies the files to the Build directory.", [
        "clean:all"
        "copy:static"
        "jade:all"
        "htmlmin:all"
        "stylesheets"
        "scripts"
    ].concat unless Debug then ["clean:production"] else []

    grunt.registerTask "watch", "Builds and watches the project for changes.", [
        "build"
        "watch_default"
    ]

【问题讨论】:

你需要包含你的 gruntfile,否则我们不知道你的测试任务使用的是什么库/代码 @Caffeinated.tech 所以你的意思是我必须先上传gruntfile.coffee 文件,对吧? 是的,这是您定义test 任务的地方。否则我们不知道是什么导致了您的错误。 @Caffeinated.tech 实际上在 gruntfile.coffee 文件中没有 test,我只是按照 grunt 命令显示使用 grunt test 启动项目..我已经在我的问题中更新了 grunt 文件,请检查。 【参考方案1】:

它引发了一个错误,因为这是在您的 gruntfile.coffee 中定义此任务的方式:

grunt.registerTask "test", "Run unit testing.", ->
    grunt.fail.fatal "Unit testing is not implemented yet" # TODO

请向维护此项目的人员询问更多详细信息。

【讨论】:

我可以知道我应该从开发者那里得到什么吗? 我的猜测是该 gruntfile 中的指令和任务不完整或已过时。要求澄清是否有任何测试,如果有,如何运行。

以上是关于grunt test - 致命错误:尚未实施单元测试的主要内容,如果未能解决你的问题,请参考以下文章

导致此错误的原因 - “致命错误:无法找到本地咕噜声”

Grunt watch 错误 - 等待...致命错误:观看 ENOSPC

Grunt Watch致命错误:听EACCES和livereload

致命错误:spawn cmd ENOENT -- grunt serve

使用grunt-sass编译node-sass,我得到错误“致命错误:”原始“参数必须是类型函数。”

线程 1:致命错误:init(coder:) 尚未实现