Files
cypress/packages/server/test/unit/specs_spec.coffee
T
Gleb Bahmutov b3e40b08cd allow list of search patterns in testFiles config option (#5402)
* WIP: log spec search steps

* add multiple files via glob test

* allow testFiles to be a string or a list of strings to match

* failing config tests: testFiles type change

Change `testFiles` from a string to either a string **or** array of strings; following similar pattern as `ignoreTestFiles`

* testFiles type change passing tests

* update verbiage related to testFiles type change

* enable running integration tests locally

See https://github.com/paulmillr/chokidar/issues/855 for more details.

* integration tests; failing

Seems to fail for similar reason as #4543 and is likely resolved with PR #4849

* correct test verbiage

Distinguish between the two tests; as they are subtly different.

* update TS types for testFiles type change

Updated the comments, but forgot to update the actual type. This commit rectifies that.

* correct CLI syntax in test

`--config` was not being passed the appropriate value. Now matches other test cases; such as that found in [args_spec](https://github.com/cypress-io/cypress/blob/92b91fe514e5ff6286b4d4e26d2df23062bdf869/packages/server/test/unit/args_spec.coffee#L210)

* remove unsupported syntax from tests

From looking at other tests, it does not appear that the syntax `--config=testFiles=glob1,glob2` is current supported. Removing the test for this test case.

* test the correct config value

Previously was testing `ignoreTestFiles` instead of `testFies`

* provide more accurate test assertion

* correct config's `testFiles` type

Should be a string or an array of strings.

* remove unnecessary newline

* tweak verbiage to better align with intention

Co-Authored-By: Ben Kucera <14625260+Bkucera@users.noreply.github.com>


Co-authored-by: Andrew Smith <andrew@andrew.codes>
2019-10-31 11:26:47 -04:00

114 lines
3.9 KiB
CoffeeScript

require("../spec_helper")
R = require("ramda")
path = require("path")
files = require("#{root}lib/files")
config = require("#{root}lib/config")
specsUtil = require("#{root}lib/util/specs")
FixturesHelper = require("#{root}/test/support/helpers/fixtures")
debug = require("debug")("test")
describe "lib/util/specs", ->
beforeEach ->
FixturesHelper.scaffold()
@todosPath = FixturesHelper.projectPath("todos")
config.get(@todosPath)
.then (cfg) =>
@config = cfg
afterEach ->
FixturesHelper.remove()
context ".find", ->
checkFoundSpec = (foundSpec) ->
if not path.isAbsolute(foundSpec.absolute)
throw new Error("path to found spec should be absolute #{JSON.stringify(foundSpec)}")
it "returns absolute filenames", ->
specsUtil
.find(@config)
.then (R.forEach(checkFoundSpec))
it "handles fixturesFolder being false", ->
@config.fixturesFolder = false
fn = => specsUtil.find(@config)
expect(fn).not.to.throw()
it "by default, returns all files as long as they have a name and extension", ->
config.get(FixturesHelper.projectPath("various-file-types"))
.then (cfg) ->
specsUtil.find(cfg)
.then (files) ->
expect(files.length).to.equal(3)
expect(files[0].name).to.equal("coffee_spec.coffee")
expect(files[1].name).to.equal("js_spec.js")
expect(files[2].name).to.equal("ts_spec.ts")
it "returns files matching config.testFiles", ->
config.get(FixturesHelper.projectPath("various-file-types"))
.then (cfg) ->
cfg.testFiles = "**/*.coffee"
specsUtil.find(cfg)
.then (files) ->
expect(files.length).to.equal(1)
expect(files[0].name).to.equal("coffee_spec.coffee")
it "uses glob to process config.testFiles", ->
config.get(FixturesHelper.projectPath("various-file-types"))
.then (cfg) ->
cfg.testFiles = "{coffee_*.coffee,js_spec.js}"
specsUtil.find(cfg)
.then (files) ->
debug("found spec files %o", files)
expect(files.length).to.equal(2)
expect(files[0].name).to.equal("coffee_spec.coffee")
expect(files[1].name).to.equal("js_spec.js")
it "allows array in config.testFiles", ->
config.get(FixturesHelper.projectPath("various-file-types"))
.then (cfg) ->
cfg.testFiles = ["coffee_*.coffee", "js_spec.js"]
specsUtil.find(cfg)
.then (files) ->
debug("found spec files %o", files)
expect(files.length).to.equal(2)
expect(files[0].name).to.equal("coffee_spec.coffee")
expect(files[1].name).to.equal("js_spec.js")
it "filters using specPattern", ->
config.get(FixturesHelper.projectPath("various-file-types"))
.then (cfg) ->
specPattern = [
path.join(cfg.projectRoot, "cypress", "integration", "js_spec.js")
]
specsUtil.find(cfg, specPattern)
.then (files) ->
expect(files.length).to.equal(1)
expect(files[0].name).to.equal("js_spec.js")
it "filters using specPattern as array of glob patterns", ->
config.get(FixturesHelper.projectPath("various-file-types"))
.then (cfg) ->
debug("test config testFiles is %o", cfg.testFiles)
specPattern = [
path.join(cfg.projectRoot, "cypress", "integration", "js_spec.js")
path.join(cfg.projectRoot, "cypress", "integration", "ts*")
]
specsUtil.find(cfg, specPattern)
.then (files) ->
expect(files.length).to.equal(2)
expect(files[0].name).to.equal("js_spec.js")
expect(files[1].name).to.equal("ts_spec.ts")
it "properly handles directories with names including '.'", ->
config.get(FixturesHelper.projectPath("odd-directory-name"))
.then (cfg) ->
specsUtil.find(cfg)
.then (files) ->
expect(files.length).to.equal(1)
expect(files[0].name).to.equal("1.0/sample_spec.js")