Skip to content

Commit

Permalink
test(rsbuild-plugin-angular): test devkit for different ng versions
Browse files Browse the repository at this point in the history
  • Loading branch information
BioPhoton committed Jan 12, 2025
1 parent 1abbd3a commit 67ff32f
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
import { SourceFileCache } from './source-file-cache';
import { SourceFileCache } from '../utils/source-file-cache';
export interface CompilerPluginOptions {
sourcemap: boolean;
tsconfig: string;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { describe, expect } from 'vitest';

vi.mock('@angular/compiler-cli', async () => {
const actual = await vi.importActual('@angular/compiler-cli');
return {
...actual,
VERSION: {
major: 16,
minor: 4,
patch: 2,
},
};
});

describe('devkit importing an angular version >=16 & <18', async () => {
// @TODO fins a way to mock require calls instead of testing the error
it('should return the exports', async () => {
expect(import('./devkit.ts')).rejects.toThrow(
'@angular-devkit/build-angular/src/tools/esbuild/angular/compiler-plugin.js'
);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { describe, expect } from 'vitest';

vi.mock('@angular/compiler-cli', async () => {
const actual = await vi.importActual('@angular/compiler-cli');
return {
...actual,
VERSION: {
major: 19,
minor: 4,
patch: 2,
},
};
});

describe('devkit importing an angular version >=19', async () => {
it('should return the exports', async () => {
expect(import('./devkit.ts')).resolves.toStrictEqual(
expect.objectContaining({
JavaScriptTransformer: expect.any(Function),
SourceFileCache: expect.any(Function),
angularMajor: 19,
angularMinor: 4,
angularPatch: 2,
createJitResourceTransformer: expect.any(Function),
})
);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { describe, expect } from 'vitest';

vi.mock('@angular/compiler-cli', async () => {
const actual = await vi.importActual('@angular/compiler-cli');
return {
...actual,
VERSION: {
major: 15,
minor: 4,
patch: 2,
},
};
});

describe('devkit importing an angular version >=15 & <16', async () => {
// @TODO fins a way to mock require calls instead of testing the error
it('should return the exports', async () => {
expect(import('./devkit.ts')).rejects.toThrow(
'@angular-devkit/build-angular/src/builders/browser-esbuild/compiler-plugin.js'
);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
normalizeQuotes,
} from './utils';
import { SyntaxKind } from 'ts-morph';
import { sourceFileFromCode } from 'testing-utils';
import { sourceFileFromCode } from '@ng-rspack/testing-utils';

vi.mock('node:os', async (importOriginal) => {
const actual = await importOriginal<typeof osModule>();
Expand Down

0 comments on commit 67ff32f

Please sign in to comment.