Atom 'spec' files not being tested

2019-09-11 03:33发布

Following up from my previous question, here, I am trying to get 'spec' files registered by Atom, which I have succeeded in, however now, no matter how many describe and it's I do, it doesn't do anything when I test it.

I use the command, apm test, and all I get is:

[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

Judging by the spec file (which is definitely being registered, as it complains when it doesn't exist), I should have 3 tests run.

My spec file is as follows... (Syntax Highlighter package)

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']

My file structure is as follows:

  • language-jazz
    • grammars
      • jazz.cson
    • snippets
      • language-jazz.cson
    • spec
      • jazz-spec.coffee
    • package.json
    • Other GitHub and Travis CI stuff.

1条回答
戒情不戒烟
2楼-- · 2019-09-11 04:04

The problem is the indentation and structure of your tests in your spec, bear in mind that in CoffeeScript whitespace is significant and the run blocks are used to encapsulate blocks of the code not to group it statements.

So the spec should be:

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']

I've tested this locally and it shows up as three failing tests, as I have implemented your grammar.

查看更多
登录 后发表回答