|
| 1 | +/** |
| 2 | + * Copyright (c) Meta Platforms, Inc. and affiliates. |
| 3 | + * |
| 4 | + * This source code is licensed under the MIT license found in the |
| 5 | + * LICENSE file in the root directory of this source tree. |
| 6 | + * |
| 7 | + * @format |
| 8 | + */ |
| 9 | + |
| 10 | +'use strict'; |
| 11 | + |
| 12 | +const { |
| 13 | + combineSchemasInFileList, |
| 14 | +} = require('../combine-js-to-schema'); |
| 15 | +const fs = require('fs'); |
| 16 | +const os = require('os'); |
| 17 | +const path = require('path'); |
| 18 | + |
| 19 | +describe('combine-js-to-schema', () => { |
| 20 | + let tmpdir; |
| 21 | + |
| 22 | + beforeEach(() => { |
| 23 | + tmpdir = fs.mkdtempSync(path.join(os.tmpdir(), 'codegen-combine-')); |
| 24 | + }); |
| 25 | + |
| 26 | + afterEach(() => { |
| 27 | + fs.rmSync(tmpdir, {recursive: true, force: true}); |
| 28 | + }); |
| 29 | + |
| 30 | + it('expands symlinked directories into source files', () => { |
| 31 | + const sourceDir = path.join(tmpdir, 'source'); |
| 32 | + const symlinkDir = path.join(tmpdir, 'symlink'); |
| 33 | + fs.mkdirSync(sourceDir); |
| 34 | + fs.symlinkSync( |
| 35 | + sourceDir, |
| 36 | + symlinkDir, |
| 37 | + process.platform === 'win32' ? 'junction' : 'dir', |
| 38 | + ); |
| 39 | + |
| 40 | + fs.writeFileSync( |
| 41 | + path.join(sourceDir, 'NativeSample.ts'), |
| 42 | + ` |
| 43 | + import type {TurboModule} from 'react-native'; |
| 44 | + import * as TurboModuleRegistry from 'TurboModuleRegistry'; |
| 45 | +
|
| 46 | + export interface Spec extends TurboModule { |
| 47 | + sampleMethod: () => void; |
| 48 | + } |
| 49 | +
|
| 50 | + export default TurboModuleRegistry.get<Spec>('Sample'); |
| 51 | + `, |
| 52 | + ); |
| 53 | + |
| 54 | + const schema = combineSchemasInFileList( |
| 55 | + [symlinkDir], |
| 56 | + null, |
| 57 | + null, |
| 58 | + 'SampleSpec', |
| 59 | + ); |
| 60 | + |
| 61 | + expect(Object.keys(schema.modules)).toEqual(['NativeSample']); |
| 62 | + }); |
| 63 | +}); |
0 commit comments