|
| 1 | +/* |
| 2 | + * @adonisjs/assembler |
| 3 | + * |
| 4 | + * (c) AdonisJS |
| 5 | + * |
| 6 | + * For the full copyright and license information, please view the LICENSE |
| 7 | + * file that was distributed with this source code. |
| 8 | + */ |
| 9 | + |
| 10 | +import { test } from '@japa/runner' |
| 11 | +import { join } from 'path' |
| 12 | +import { Kernel } from '@adonisjs/ace' |
| 13 | +import { Filesystem } from '@poppinss/dev-utils' |
| 14 | +import { Application } from '@adonisjs/application' |
| 15 | +import { files } from '@adonisjs/sink' |
| 16 | +import CreateSuite from '../commands/Make/Suite' |
| 17 | + |
| 18 | +const fs = new Filesystem(join(__dirname, '__app')) |
| 19 | + |
| 20 | +test.group('Make Suite', (group) => { |
| 21 | + group.each.teardown(async () => { |
| 22 | + await fs.cleanup() |
| 23 | + }) |
| 24 | + |
| 25 | + test('Should add suite to RcFile and create sample test', async ({ assert }) => { |
| 26 | + await fs.ensureRoot() |
| 27 | + const app = new Application(fs.basePath, 'test', {}) |
| 28 | + const suiteName = 'my-super-suite' |
| 29 | + const createSuite = new CreateSuite(app, new Kernel(app).mockConsoleOutput()) |
| 30 | + |
| 31 | + createSuite.suite = suiteName |
| 32 | + await createSuite.run() |
| 33 | + |
| 34 | + const sampleTestExist = fs.fsExtra.pathExistsSync( |
| 35 | + join(fs.basePath, `tests/${suiteName}/test.spec.ts`) |
| 36 | + ) |
| 37 | + assert.isTrue(sampleTestExist) |
| 38 | + |
| 39 | + const rcFile = new files.AdonisRcFile(fs.basePath) |
| 40 | + assert.deepEqual(rcFile.get('tests.suites'), [ |
| 41 | + { |
| 42 | + name: suiteName, |
| 43 | + files: [`tests/${suiteName}/**/*.spec(.ts|.js)`], |
| 44 | + timeout: 60000, |
| 45 | + }, |
| 46 | + ]) |
| 47 | + }) |
| 48 | + |
| 49 | + test("Shouldn't add suite to RcFile if it already exists", async ({ assert }) => { |
| 50 | + await fs.ensureRoot() |
| 51 | + const app = new Application(fs.basePath, 'test', {}) |
| 52 | + const suiteName = 'my-super-suite' |
| 53 | + const createSuite = new CreateSuite(app, new Kernel(app).mockConsoleOutput()) |
| 54 | + |
| 55 | + createSuite.suite = suiteName |
| 56 | + await createSuite.run() |
| 57 | + await createSuite.run() |
| 58 | + await createSuite.run() |
| 59 | + |
| 60 | + const rcFile = new files.AdonisRcFile(fs.basePath) |
| 61 | + assert.deepEqual(rcFile.get('tests.suites'), [ |
| 62 | + { |
| 63 | + name: suiteName, |
| 64 | + files: [`tests/${suiteName}/**/*.spec(.ts|.js)`], |
| 65 | + timeout: 60000, |
| 66 | + }, |
| 67 | + ]) |
| 68 | + }) |
| 69 | + |
| 70 | + test("Shouldn't add a sample file if specified", async ({ assert }) => { |
| 71 | + await fs.ensureRoot() |
| 72 | + const app = new Application(fs.basePath, 'test', {}) |
| 73 | + |
| 74 | + const suiteName = 'my-super-suite' |
| 75 | + const createSuite = new CreateSuite(app, new Kernel(app).mockConsoleOutput()) |
| 76 | + |
| 77 | + createSuite.suite = suiteName |
| 78 | + createSuite.withExampleTest = false |
| 79 | + await createSuite.run() |
| 80 | + |
| 81 | + const sampleTestExist = fs.fsExtra.pathExistsSync( |
| 82 | + join(fs.basePath, `tests/${suiteName}/test.spec.ts`) |
| 83 | + ) |
| 84 | + |
| 85 | + assert.isFalse(sampleTestExist) |
| 86 | + }) |
| 87 | + |
| 88 | + test('Custom location - {location}') |
| 89 | + .with([ |
| 90 | + { location: 'tests/unit/**.spec.ts', filePath: 'tests/unit/test.spec.ts' }, |
| 91 | + { location: 'tests/a/**/*.spec.ts', filePath: 'tests/a/test.spec.ts' }, |
| 92 | + { |
| 93 | + location: 'tests/a/b/c/**.spec.ts', |
| 94 | + filePath: 'tests/a/b/c/test.spec.ts', |
| 95 | + }, |
| 96 | + { |
| 97 | + location: 'tests/my-tests', |
| 98 | + globPattern: 'tests/my-tests/**/*.spec(.ts|.js)', |
| 99 | + filePath: 'tests/my-tests/test.spec.ts', |
| 100 | + }, |
| 101 | + { |
| 102 | + location: '', |
| 103 | + globPattern: 'tests/my-super-suite/**/*.spec(.ts|.js)', |
| 104 | + filePath: 'tests/my-super-suite/test.spec.ts', |
| 105 | + }, |
| 106 | + ]) |
| 107 | + .run(async ({ assert }, { location, filePath, globPattern }) => { |
| 108 | + await fs.ensureRoot() |
| 109 | + const app = new Application(fs.basePath, 'test', {}) |
| 110 | + const suiteName = 'my-super-suite' |
| 111 | + const createSuite = new CreateSuite(app, new Kernel(app).mockConsoleOutput()) |
| 112 | + |
| 113 | + createSuite.suite = suiteName |
| 114 | + createSuite.location = location |
| 115 | + |
| 116 | + await createSuite.run() |
| 117 | + |
| 118 | + const sampleTestExist = fs.fsExtra.pathExistsSync(join(fs.basePath, filePath)) |
| 119 | + assert.isTrue(sampleTestExist) |
| 120 | + |
| 121 | + const rcFile = new files.AdonisRcFile(fs.basePath) |
| 122 | + assert.deepEqual(rcFile.get('tests.suites'), [ |
| 123 | + { |
| 124 | + name: suiteName, |
| 125 | + files: [globPattern || location], |
| 126 | + timeout: 60000, |
| 127 | + }, |
| 128 | + ]) |
| 129 | + }) |
| 130 | +}) |
0 commit comments