v7
1// Copyright 2022 Google LLC
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// https://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15import fs from 'node:fs'
16import { suite } from 'uvu'
17import * as assert from 'uvu/assert'
18import { globby } from 'globby'
19
20const test = suite('extra')
21
22test('every file should have a license', async () => {
23 const files = await globby(['**/*.{ts,js,mjs}'], {
24 gitignore: true,
25 onlyFiles: true,
26 cwd: process.cwd(),
27 followSymbolicLinks: false,
28 })
29 for (const file of files) {
30 const content = fs.readFileSync(file).toString()
31 assert.match(
32 content.replace(/\d{4}/g, 'YEAR'),
33 '// Copyright YEAR Google LLC\n' +
34 '//\n' +
35 '// Licensed under the Apache License, Version 2.0 (the "License");\n' +
36 '// you may not use this file except in compliance with the License.\n' +
37 '// You may obtain a copy of the License at\n' +
38 '//\n' +
39 '// https://www.apache.org/licenses/LICENSE-2.0\n' +
40 '//\n' +
41 '// Unless required by applicable law or agreed to in writing, software\n' +
42 '// distributed under the License is distributed on an "AS IS" BASIS,\n' +
43 '// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n' +
44 '// See the License for the specific language governing permissions and\n' +
45 '// limitations under the License.',
46 `No license header in ${file}.`
47 )
48 }
49})
50
51test.run()