【问题标题】:Atom 'spec' files not being tested未测试 Atom 'spec' 文件
【发布时间】:2016-09-25 03:04:08
【问题描述】:

继我之前的问题here 之后,我正在尝试获取由 Atom 注册的“规范”文件,我已经成功了,但是现在,无论有多少 describeit 我做,当我测试它时它什么也没做。

我使用命令apm test,得到的只是:

[655:0527/083825:WARNING:resource_bundle.cc(305)]  locale_file_path.empty() for locale English
[655:0527/083825:ERROR:file_io.cc(30)] read: expected 40, observed 0
[659:0527/083825:WARNING:resource_bundle.cc(305)] locale_file_path.empty() for locale English
[655:0527/083828:INFO:CONSOLE(52)] "Window load time: 2420ms", source: file:///Applications/Atom.app/Contents/Resources/app.asar/static/index.js (52)


Finished in 0.023 seconds
0 tests, 0 assertions, 0 failures, 0 skipped

Tests passed

根据规范文件(肯定被注册,因为它在不存在时会抱怨)判断,我应该运行 3 个测试。

我的规范文件如下...(语法荧光笔包)

describe "Jazz grammar", ->
  grammar = null

  beforeEach ->
    waitsForPromise ->
      atom.packages.activatePackage("language-jazz")

    runs ->
      grammar = atom.grammars.grammarForScopeName("source.jazz")

    it "parses the grammar", ->
        expect(grammar).toBeDefined()
        expect(grammar.scopeName).toBe "source.jazz"

    it "tokenises keywords", ->
        tokens = grammar.tokenizeLines('func')

        expect(tokens[0][0].value).toBe 'func'
        expect(tokens[0][0].scopes).toEqual ['source.jazz', 'storage.type.jazz']

    it "tokenizes comments inside function parameters", ->
        tokens = grammar.tokenizeLines('module test(arg1, ;; arg2)')

        expect(tokens[0][0].value).toBe 'module'
        expect(tokens[0][0].scopes).toEqual ['source.jazz', 'storage.type.jazz']
        expect(tokens[0][1].scopes).toEqual ['source.jazz', 'comment.line.jazz']

我的文件结构如下:

  • 语言-爵士
    • 语法
      • jazz.cson
    • sn-ps
      • language-jazz.cson
    • 规格
      • jazz-spec.coffee
    • package.json
    • 其他 GitHub 和 Travis CI 资料。

【问题讨论】:

    标签: coffeescript jasmine atom-editor


    【解决方案1】:

    问题在于规范中测试的缩进和结构,请记住,在 CoffeeScript 中空格很重要,run 块用于封装代码块,而不是对 it 语句进行分组。

    所以规范应该是:

    describe "Jazz grammar", ->
      grammar = null
    
      beforeEach ->
        waitsForPromise ->
          atom.packages.activatePackage("language-jazz")
    
      grammar = atom.grammars.grammarForScopeName("source.jazz")
    
      it "parses the grammar", ->
        expect(grammar).toBeDefined()
        expect(grammar.scopeName).toBe "source.jazz"
    
      it "tokenises keywords", ->
        tokens = grammar.tokenizeLines('func')
    
        expect(tokens[0][0].value).toBe 'func'
        expect(tokens[0][0].scopes).toEqual ['source.jazz', 'storage.type.jazz']
    
      it "tokenizes comments inside function parameters", ->
        tokens = grammar.tokenizeLines('module test(arg1, ;; arg2)')
    
        expect(tokens[0][0].value).toBe 'module'
        expect(tokens[0][0].scopes).toEqual ['source.jazz', 'storage.type.jazz']
        expect(tokens[0][1].scopes).toEqual ['source.jazz', 'comment.line.jazz']
    

    我已经在本地对此进行了测试,它显示为三个失败的测试,因为我已经实现了你的语法。

    【讨论】:

    • 抱歉,我刚刚从language-python 制作了一个模板。我使用的是四个空格的缩进,但是您使用的是两个空格的缩进。无论哪种方式,我都对答案如此简单感到畏缩,再次非常感谢理查德;现在我只需要诊断故障...
    • 我重新添加了runs ->,它似乎已经修复了“grammer.tokenizeLines` not found 错误。请查看:github.com/atom/language-python/blob/master/spec/… runs
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-12-13
    • 2017-11-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多