-
Notifications
You must be signed in to change notification settings - Fork 6
/
translations-collect.js
99 lines (80 loc) · 2.63 KB
/
translations-collect.js
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
/**
* @license Copyright (c) 2020-2022, CKSource - Frederico Knabben. All rights reserved.
* For licensing, see LICENSE.md.
*/
'use strict';
const sinon = require( 'sinon' );
const expect = require( 'chai' ).expect;
const mockery = require( 'mockery' );
describe( 'lib/tasks/translations-collect', () => {
let translationsCollect, stubs;
beforeEach( () => {
mockery.enable( {
useCleanCache: true,
warnOnReplace: false,
warnOnUnregistered: false
} );
stubs = {
devEnv: {
createPotFiles: sinon.stub()
},
path: {
join: sinon.stub().callsFake( ( ...chunks ) => chunks.join( '/' ) )
},
glob: {
sync: sinon.stub()
}
};
mockery.registerMock( 'path', stubs.path );
mockery.registerMock( 'glob', stubs.glob );
mockery.registerMock( '@ckeditor/ckeditor5-dev-env', stubs.devEnv );
translationsCollect = require( '../../lib/tasks/translations-collect' );
} );
afterEach( () => {
sinon.restore();
mockery.disable();
} );
it( 'should be a function', () => {
expect( translationsCollect ).to.be.a( 'function' );
} );
it( 'creates translation files', () => {
const sourceFiles = [
'/workspace/ckeditor5-foo/src/index.js',
'/workspace/ckeditor5-foo/src/myplugin.js'
];
stubs.glob.sync.returns( sourceFiles );
stubs.devEnv.createPotFiles.returns( 'OK' );
const results = translationsCollect( {
cwd: '/workspace'
} );
expect( results ).to.equal( 'OK' );
expect( stubs.glob.sync.calledOnce ).to.equal( true );
expect( stubs.glob.sync.firstCall.firstArg ).to.equal( '/workspace/src/**/*.js' );
expect( stubs.devEnv.createPotFiles.calledOnce ).to.equal( true );
expect( stubs.devEnv.createPotFiles.firstCall.firstArg ).to.deep.equal( {
// Verify results returned by `glob.sync()`.
sourceFiles,
// Verify a path to the `@ckeditor/ckeditor5-core` package.
corePackagePath: 'node_modules/@ckeditor/ckeditor5-core',
// Verify ignoring unused contexts from the `@ckeditor/ckeditor5-core` package.
ignoreUnusedCorePackageContexts: true,
// Verify a path where to look for packages.
packagePaths: [
'/workspace'
],
// Verify the license header in translation files.
skipLicenseHeader: true,
// Verify a path where translations will be stored.
translationsDirectory: '/workspace/tmp/.transifex'
} );
} );
it( 'passes posix paths to glob', () => {
stubs.devEnv.createPotFiles.returns( 'OK' );
const results = translationsCollect( {
cwd: 'C:\\workspace'
} );
expect( results ).to.equal( 'OK' );
expect( stubs.glob.sync.calledOnce ).to.equal( true );
expect( stubs.glob.sync.firstCall.firstArg ).to.equal( 'C:/workspace/src/**/*.js' );
} );
} );