-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Expand file tree
/
Copy pathjs-executor-node.test.ts
More file actions
193 lines (160 loc) · 4.98 KB
/
js-executor-node.test.ts
File metadata and controls
193 lines (160 loc) · 4.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
import {
cleanupProject,
newProject,
runCLI,
uniq,
updateFile,
updateJson,
} from '@nx/e2e-utils';
import { join } from 'path';
describe('js:node executor', () => {
let scope: string;
beforeAll(() => {
scope = newProject({
packages: ['@nx/js', '@nx/node', '@nx/esbuild', '@nx/webpack'],
});
});
afterAll(() => cleanupProject());
it('should log out the error', async () => {
const esbuildLib = uniq('esbuildlib');
runCLI(
`generate @nx/js:lib libs/${esbuildLib} --bundler=esbuild --no-interactive`
);
updateFile(`libs/${esbuildLib}/src/index.ts`, () => {
return `
console.log('Hello from my library!');
throw new Error('This is an error');
`;
});
updateJson(join('libs', esbuildLib, 'project.json'), (config) => {
config.targets['run-node'] = {
executor: '@nx/js:node',
options: {
buildTarget: `${esbuildLib}:build`,
watch: false,
},
};
return config;
});
const output = runCLI(`run ${esbuildLib}:run-node`, {
redirectStderr: true,
silenceError: true,
});
expect(output).toContain('Hello from my library!');
expect(output).toContain('This is an error');
}, 240_000);
// TODO: investigate this failure
xit('should execute library compiled with rollup', async () => {
const rollupLib = uniq('rolluplib');
runCLI(
`generate @nx/js:lib libs/${rollupLib} --bundler=rollup --no-interactive`
);
updateFile(`libs/${rollupLib}/src/index.ts`, () => {
return `
console.log('Hello from my library!');
`;
});
updateJson(join('libs', rollupLib, 'project.json'), (config) => {
config.targets['run-node'] = {
executor: '@nx/js:node',
options: {
buildTarget: `${rollupLib}:build`,
watch: false,
},
};
return config;
});
const output = runCLI(`run ${rollupLib}:run-node`);
expect(output).toContain('Hello from my library!');
}, 240_000);
it('should execute library compiled with tsc', async () => {
const tscLib = uniq('tsclib');
runCLI(`generate @nx/js:lib libs/${tscLib} --bundler=tsc --no-interactive`);
updateFile(`libs/${tscLib}/src/index.ts`, () => {
return `
console.log('Hello from my tsc library!');
`;
});
updateJson(join('libs', tscLib, 'project.json'), (config) => {
config.targets['run-node'] = {
executor: '@nx/js:node',
options: {
buildTarget: `${tscLib}:build`,
watch: false,
},
};
return config;
});
const output = runCLI(`run ${tscLib}:run-node`);
expect(output).toContain('Hello from my tsc library!');
}, 240_000);
it('should execute library compiled with swc', async () => {
const swcLib = uniq('swclib');
runCLI(`generate @nx/js:lib libs/${swcLib} --bundler=swc --no-interactive`);
updateFile(`libs/${swcLib}/src/index.ts`, () => {
return `
console.log('Hello from my swc library!');
`;
});
updateJson(join('libs', swcLib, 'project.json'), (config) => {
config.targets['run-node'] = {
executor: '@nx/js:node',
options: {
buildTarget: `${swcLib}:build`,
watch: false,
},
};
return config;
});
const output = runCLI(`run ${swcLib}:run-node`);
expect(output).toContain('Hello from my swc library!');
}, 240_000);
it('should execute webpack app', async () => {
const webpackProject = uniq('webpackproject');
runCLI(
`generate @nx/node:application apps/${webpackProject} --bundler=webpack --no-interactive`
);
updateFile(`apps/${webpackProject}/src/main.ts`, () => {
return `
console.log('Hello from my webpack app!');
`;
});
updateJson(join('apps', webpackProject, 'project.json'), (config) => {
config.targets['run-node'] = {
executor: '@nx/js:node',
options: {
buildTarget: `${webpackProject}:build`,
watch: false,
},
};
return config;
});
const output = runCLI(`run ${webpackProject}:run-node`);
expect(output).toContain('Hello from my webpack app!');
}, 240_000);
it('should execute an esbuild tool', async () => {
const esbuildLib = uniq('esbuildlib');
runCLI(
`generate @nx/js:lib libs/${esbuildLib} --bundler=esbuild --no-interactive`
);
updateFile(`libs/${esbuildLib}/src/index.ts`, () => {
return `
setTimeout(() => {
console.log('Hello from my esbuild library!');
}, 1000);
`;
});
updateJson(join('libs', esbuildLib, 'project.json'), (config) => {
config.targets['run-node'] = {
executor: '@nx/js:node',
options: {
buildTarget: `${esbuildLib}:build`,
watch: false,
},
};
return config;
});
const output = runCLI(`run ${esbuildLib}:run-node`);
expect(output).toContain('Hello from my esbuild library!');
}, 240_000);
});