需要使用jasmine获取文件路径

时间:2016-09-20 14:40:02

标签: javascript node.js jasmine protractor

我需要获取文件名。

我看到jasmine.getEnv().currentSpec.description会返回spec.js个描述。 同样,我需要获得spec.js完整路径。是否可以获取文件路径?

1 个答案:

答案 0 :(得分:3)

jasmine未提供对正在运行规范的文件的引用。 env(来自getEnv())对象仅提供有关规范和套件的信息,但不提供有关文件的信息。

您可以通过利用文件本身内的__filename全局来获取对文件完整路径的引用。例如:

const jasmine = require('jasmine-node');
console.log(__filename);

describe('description for spec', () => {
  it('should do stuff', () => {
    console.log(jasmine.getEnv());
  });
});

以下是env对象的摘要:

{ currentSpec:
   { id: 0,
     env: [Circular],
     suite:
      { id: 0,
        description: 'description for spec',
        queue: [Object],
        parentSuite: null,
        env: [Circular],
        before_: [],
        after_: [],
        children_: [Object],
        suites_: [],
        specs_: [Object],
        exclusive_: 0 },
     description: 'should do stuff',
     queue:
      { env: [Circular],
        ensured: [Object],
        blocks: [Object],
        running: true,
        index: 0,
        offset: 0,
        abort: false,
        onComplete: [Function] },
     afterCallbacks: [],
     spies_: [],
     results_:
      { totalCount: 0,
        passedCount: 0,
        failedCount: 0,
        skipped: false,
        items_: [],
        description: 'should do stuff' },
     matchersClass: null,
     exclusive_: 0 },
  currentSuite: null,
  currentRunner_:
   { env: [Circular],
     queue:
      { env: [Circular],
        ensured: [Object],
        blocks: [Object],
        running: true,
        index: 0,
        offset: 0,
        abort: false,
        onComplete: [Function] },
     before_: [],
     after_: [],
     suites_: [ [Object] ] },
  reporter: { subReporters_: [ [Object] ] },
  updateInterval: 250,
  defaultTimeoutInterval: 5000,
  lastUpdate: 0,
  specFilter: [Function],
  nextSpecId_: 1,
  nextSuiteId_: 1,
  equalityTesters_: [],
  exclusive_: 0,
  matchersClass: [Function] }