|
| 1 | +import { formatDuration, getFilenameParts } from '../../../src/lib/util' |
| 2 | + |
| 3 | +const compare = (filename, array) => { |
| 4 | + expect(getFilenameParts(filename)).to.deep.equal(array) |
| 5 | +} |
| 6 | + |
| 7 | +describe('utils', () => { |
| 8 | + context('formatDuration', () => { |
| 9 | + it('formats no time', () => { |
| 10 | + expect(formatDuration(0)).to.equal('--') |
| 11 | + }) |
| 12 | + |
| 13 | + it('formats time of <1s', () => { |
| 14 | + expect(formatDuration(1)).to.equal('1ms') |
| 15 | + expect(formatDuration(999)).to.equal('999ms') |
| 16 | + }) |
| 17 | + |
| 18 | + it('formats time of >=1s', () => { |
| 19 | + expect(formatDuration(1000)).to.equal('00:01') |
| 20 | + expect(formatDuration(1400)).to.equal('00:01') |
| 21 | + expect(formatDuration(35620)).to.equal('00:36') |
| 22 | + expect(formatDuration(59200)).to.equal('00:59') |
| 23 | + }) |
| 24 | + |
| 25 | + it('formats time of >=1m', () => { |
| 26 | + expect(formatDuration(60000)).to.equal('01:00') |
| 27 | + expect(formatDuration(600000)).to.equal('10:00') |
| 28 | + expect(formatDuration(3599000)).to.equal('59:59') |
| 29 | + }) |
| 30 | + |
| 31 | + it('formats time of >=1h', () => { |
| 32 | + expect(formatDuration(3600000)).to.equal('1:00:00') |
| 33 | + expect(formatDuration(4200000)).to.equal('1:10:00') |
| 34 | + expect(formatDuration(7199000)).to.equal('1:59:59') |
| 35 | + }) |
| 36 | + |
| 37 | + it('displays larger times in hours', () => { |
| 38 | + expect(formatDuration(360000000)).to.equal('100:00:00') |
| 39 | + }) |
| 40 | + }) |
| 41 | + |
| 42 | + context('getFilenameParts', () => { |
| 43 | + it('splits basic filenames', () => { |
| 44 | + compare('something.foo.ts', ['something.foo', '.ts']) |
| 45 | + compare('first-user.js', ['first-user', '.js']) |
| 46 | + compare('model.coffee', ['model', '.coffee']) |
| 47 | + }) |
| 48 | + |
| 49 | + it('handles .spec, .test, and .cy', () => { |
| 50 | + compare('basic.spec.ts', ['basic', '.spec.ts']) |
| 51 | + compare('spies_stubs_clocks.spec.js', ['spies_stubs_clocks', '.spec.js']) |
| 52 | + compare('newIssuanceWorkflow.test.js', ['newIssuanceWorkflow', '.test.js']) |
| 53 | + compare('Button.cy.js', ['Button', '.cy.js']) |
| 54 | + }) |
| 55 | + |
| 56 | + it('does not consider "_spec" to be part of the extension', () => { |
| 57 | + // might want to change this functionality later, but for now this is working as intended |
| 58 | + compare('warning_spec.js', ['warning_spec', '.js']) |
| 59 | + }) |
| 60 | + |
| 61 | + it('behaves as expected if "spec" is in the filename', () => { |
| 62 | + compare('spec.ts', ['spec', '.ts']) |
| 63 | + compare('spec_spec.ts', ['spec_spec', '.ts']) |
| 64 | + }) |
| 65 | + |
| 66 | + it('handles no file extension', () => { |
| 67 | + compare('no-extension', ['no-extension', '']) |
| 68 | + }) |
| 69 | + |
| 70 | + it('strips directory path', () => { |
| 71 | + compare('unit/spec_split_spec.ts', ['spec_split_spec', '.ts']) |
| 72 | + compare('dir/unit/spec_split_spec.ts', ['spec_split_spec', '.ts']) |
| 73 | + }) |
| 74 | + |
| 75 | + it('displays filename with special characters', () => { |
| 76 | + compare('cypress/integration/meta_&%_spec.ts', ['meta_&%_spec', '.ts']) |
| 77 | + }) |
| 78 | + |
| 79 | + it('handles an unexpected number of extensions', () => { |
| 80 | + compare('reporter.hooks.spec.js', ['reporter.hooks', '.spec.js']) |
| 81 | + }) |
| 82 | + }) |
| 83 | +}) |
0 commit comments