|
| 1 | +const logger = require('consola'); |
| 2 | +const path = require('path'); |
| 3 | +const temp = require('temp'); |
| 4 | +const fs = require('fs-extra'); |
| 5 | +const utils = require('../../src/utils.js'); |
| 6 | +const task = require('../../src/tasks/scaffold.js'); |
| 7 | + |
| 8 | +describe('task > make:*', () => { |
| 9 | + const root = temp.mkdirSync('osjs-cli-jest'); |
| 10 | + const fname = str => path.resolve(root, str); |
| 11 | + |
| 12 | + const defaults = utils.createOptions({root}); |
| 13 | + |
| 14 | + const options = utils.resolveOptions(defaults, { |
| 15 | + discover: [ |
| 16 | + path.resolve(__dirname, '../../__mocks__/packages') |
| 17 | + ] |
| 18 | + }); |
| 19 | + |
| 20 | + const runTask = (name, args = {}) => task[name] |
| 21 | + .action({ |
| 22 | + logger, |
| 23 | + options, |
| 24 | + args, |
| 25 | + commander: null |
| 26 | + }); |
| 27 | + |
| 28 | + const basicScaffold = async (name, type) => { |
| 29 | + const filename = `my-${name}.js`; |
| 30 | + await runTask(`make:${name}`, {type, filename}); |
| 31 | + |
| 32 | + return fs.existsSync(fname(`src/${type}/${filename}`)); |
| 33 | + }; |
| 34 | + |
| 35 | + afterAll(() => fs.removeSync(root)); |
| 36 | + |
| 37 | + describe('make:auth', () => { |
| 38 | + test('should create client auth adapter', () => { |
| 39 | + return expect(basicScaffold('auth', 'client')) |
| 40 | + .resolves |
| 41 | + .toBe(true); |
| 42 | + }); |
| 43 | + |
| 44 | + test('should create server auth adapter', async () => { |
| 45 | + return expect(basicScaffold('auth', 'server')) |
| 46 | + .resolves |
| 47 | + .toBe(true); |
| 48 | + }); |
| 49 | + |
| 50 | + test('should fail when exists', async () => { |
| 51 | + return expect(basicScaffold('auth', 'server')) |
| 52 | + .rejects |
| 53 | + .toBeInstanceOf(Error); |
| 54 | + }); |
| 55 | + }); |
| 56 | + |
| 57 | + describe('make:settings', () => { |
| 58 | + test('should create client settings adapter', () => { |
| 59 | + return expect(basicScaffold('settings', 'client')) |
| 60 | + .resolves |
| 61 | + .toBe(true); |
| 62 | + }); |
| 63 | + |
| 64 | + test('should create server settings adapter', async () => { |
| 65 | + return expect(basicScaffold('settings', 'server')) |
| 66 | + .resolves |
| 67 | + .toBe(true); |
| 68 | + }); |
| 69 | + }); |
| 70 | + |
| 71 | + describe('make:provider', () => { |
| 72 | + test('should create client provider adapter', () => { |
| 73 | + return expect(basicScaffold('provider', 'client')) |
| 74 | + .resolves |
| 75 | + .toBe(true); |
| 76 | + }); |
| 77 | + |
| 78 | + test('should create server provider adapter', async () => { |
| 79 | + return expect(basicScaffold('provider', 'server')) |
| 80 | + .resolves |
| 81 | + .toBe(true); |
| 82 | + }); |
| 83 | + }); |
| 84 | + |
| 85 | + describe('make:vfs', () => { |
| 86 | + test('should create client vfs adapter', () => { |
| 87 | + return expect(basicScaffold('vfs', 'client')) |
| 88 | + .resolves |
| 89 | + .toBe(true); |
| 90 | + }); |
| 91 | + |
| 92 | + test('should create server vfs adapter', async () => { |
| 93 | + return expect(basicScaffold('vfs', 'server')) |
| 94 | + .resolves |
| 95 | + .toBe(true); |
| 96 | + }); |
| 97 | + }); |
| 98 | + |
| 99 | + describe('make:application', () => { |
| 100 | + test('should create application', async () => { |
| 101 | + await runTask('make:application', { |
| 102 | + dry: true, |
| 103 | + force: true, |
| 104 | + name: 'StandardApplication', |
| 105 | + target: 'src/packages/StandardApplication' |
| 106 | + }); |
| 107 | + |
| 108 | + expect(fs.readdirSync(fname('src/packages/StandardApplication'))) |
| 109 | + .toHaveLength(7); |
| 110 | + }); |
| 111 | + }); |
| 112 | + |
| 113 | + describe('make:iframe-application', () => { |
| 114 | + test('should create application', async () => { |
| 115 | + await runTask('make:iframe-application', { |
| 116 | + dry: true, |
| 117 | + force: true, |
| 118 | + name: 'IframeApplication', |
| 119 | + target: 'src/packages/IframeApplication' |
| 120 | + }); |
| 121 | + |
| 122 | + expect(fs.readdirSync(fname('src/packages/IframeApplication'))) |
| 123 | + .toHaveLength(6); |
| 124 | + }); |
| 125 | + }); |
| 126 | +}); |
0 commit comments