Skip to content
This repository was archived by the owner on May 1, 2020. It is now read-only.

Commit da89493

Browse files
committed
test(watch): make tests platform independent
make tests platform independent
1 parent b337e30 commit da89493

File tree

1 file changed

+18
-18
lines changed

1 file changed

+18
-18
lines changed

src/watch.spec.ts

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as path from 'path';
1+
import { join, resolve } from 'path';
22

33
import * as build from './build';
44
import { BuildContext, BuildState, ChangedFile } from './util/interfaces';
@@ -127,7 +127,7 @@ describe('watch', () => {
127127
ext: '.ts'
128128
}];
129129
context.bundleState = BuildState.SuccessfulBuild;
130-
const resolvedFilePath = path.resolve('file1.ts');
130+
const resolvedFilePath = resolve('file1.ts');
131131
context.fileCache.set(resolvedFilePath, { path: 'file1.ts', content: 'content' });
132132
watch.runBuildUpdate(context, files);
133133
expect(context.transpileState).toEqual(BuildState.RequiresUpdate);
@@ -141,7 +141,7 @@ describe('watch', () => {
141141
filePath: 'file1.ts',
142142
ext: '.ts'
143143
}];
144-
const resolvedFilePath = path.resolve('file1.ts');
144+
const resolvedFilePath = resolve('file1.ts');
145145
context.fileCache.set(resolvedFilePath, { path: 'file1.ts', content: 'content' });
146146
watch.runBuildUpdate(context, files);
147147
expect(context.transpileState).toEqual(BuildState.RequiresUpdate);
@@ -201,37 +201,37 @@ describe('watch', () => {
201201
});
202202

203203
it('should set replacePathVars when options.ignored is a string', () => {
204-
const watcher: watch.Watcher = { options: { ignored: '{{SRC}}/**/*.spec.ts' } };
205-
const context: BuildContext = { srcDir: '/some/src/' };
204+
const watcher: watch.Watcher = { options: { ignored: join('{{SRC}}', '**', '*.spec.ts') } };
205+
const context: BuildContext = { srcDir: join(process.cwd(), 'some', 'src')};
206206
watch.prepareWatcher(context, watcher);
207-
expect(watcher.options.ignored).toEqual('/some/src/**/*.spec.ts');
207+
expect(watcher.options.ignored).toEqual(join(process.cwd(), 'some', 'src', '**', '*.spec.ts'));
208208
});
209209

210210
it('should set replacePathVars when options.ignored is an array of strings', () => {
211-
const watcher: watch.Watcher = { options: { ignored: ['{{SRC}}/**/*.spec.ts', '{{SRC}}/index.html'] } };
212-
const context: BuildContext = { srcDir: '/some/src/' };
211+
const watcher: watch.Watcher = { options: { ignored: [join('{{SRC}}', '**', '*.spec.ts'), join('{{SRC}}', 'index.html')] } };
212+
const context: BuildContext = { srcDir: join(process.cwd(), 'some', 'src')};
213213
watch.prepareWatcher(context, watcher);
214-
expect((watcher.options.ignored as string[])[0]).toEqual('/some/src/**/*.spec.ts');
215-
expect((watcher.options.ignored as string[])[1]).toEqual('/some/src/index.html');
214+
expect((watcher.options.ignored as string[])[0]).toEqual(join(process.cwd(), 'some', 'src', '**', '*.spec.ts'));
215+
expect((watcher.options.ignored as string[])[1]).toEqual(join(process.cwd(), 'some', 'src', 'index.html'));
216216
});
217217

218218
it('should set replacePathVars when paths is an array', () => {
219219
const watcher: watch.Watcher = { paths: [
220-
'{{SRC}}/some/path1',
221-
'{{SRC}}/some/path2'
220+
join('{{SRC}}', 'some', 'path1'),
221+
join('{{SRC}}', 'some', 'path2')
222222
] };
223-
const context: BuildContext = { srcDir: '/some/src/' };
223+
const context: BuildContext = { srcDir: join(process.cwd(), 'some', 'src')};
224224
watch.prepareWatcher(context, watcher);
225225
expect(watcher.paths.length).toEqual(2);
226-
expect(watcher.paths[0]).toEqual('/some/src/some/path1');
227-
expect(watcher.paths[1]).toEqual('/some/src/some/path2');
226+
expect(watcher.paths[0]).toEqual(join(process.cwd(), 'some', 'src', 'some', 'path1'));
227+
expect(watcher.paths[1]).toEqual(join(process.cwd(), 'some', 'src', 'some', 'path2'));
228228
});
229229

230230
it('should set replacePathVars when paths is a string', () => {
231-
const watcher: watch.Watcher = { paths: '{{SRC}}/some/path' };
232-
const context: BuildContext = { srcDir: '/some/src/' };
231+
const watcher: watch.Watcher = { paths: join('{{SRC}}', 'some', 'path')};
232+
const context: BuildContext = { srcDir: join(process.cwd(), 'some', 'src')};
233233
watch.prepareWatcher(context, watcher);
234-
expect(watcher.paths).toEqual('/some/src/some/path');
234+
expect(watcher.paths).toEqual(join(process.cwd(), 'some', 'src', 'some', 'path'));
235235
});
236236

237237
it('should not set options.ignoreInitial if it was provided', () => {

0 commit comments

Comments
 (0)