Skip to content

Commit

Permalink
test(typescript): code in src sub-directory (#682)
Browse files Browse the repository at this point in the history
  • Loading branch information
benmccann authored Dec 7, 2020
1 parent 1818243 commit 26e2a00
Show file tree
Hide file tree
Showing 3 changed files with 121 additions and 0 deletions.
69 changes: 69 additions & 0 deletions packages/typescript/test/fixtures/src-dir/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
type FormDataMap = Map<string, string[]>;

class ReadOnlyFormData {
map: FormDataMap;

constructor(map: FormDataMap) {
this.map = map;
}

get(key: string) {
return this.map.get(key)?.[0];
}

getAll(key: string) {
return this.map.get(key);
}

has(key: string) {
return this.map.has(key);
}

*[Symbol.iterator]() {
for (const [key, value] of this.map) {
for (let i = 0; i < value.length; i += 1) {
yield [key, value[i]];
}
}
}

*entries() {
for (const [key, value] of this.map) {
for (let i = 0; i < value.length; i += 1) {
yield [key, value[i]];
}
}
}

*keys() {
for (const [key, value] of this.map) {
for (let i = 0; i < value.length; i += 1) {
yield key;
}
}
}

*values() {
for (const [, value] of this.map) {
for (let i = 0; i < value.length; i += 1) {
yield value;
}
}
}
}

export default function() {
const map: FormDataMap = new Map();

return {
append(key: string, value: string) {
if (map.has(key)) {
(map.get(key) as string[]).push(value);
} else {
map.set(key, [value]);
}
},

data: new ReadOnlyFormData(map)
};
}
24 changes: 24 additions & 0 deletions packages/typescript/test/fixtures/src-dir/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"compilerOptions": {
"lib": ["es2020"],
"outDir": "dist",
"target": "es2020",

"skipLibCheck": true,
"declaration": true,

"noEmitOnError": true,
"noErrorTruncation": true,

"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"allowSyntheticDefaultImports": true,

"strict": true,
"noImplicitThis": true,
"noUnusedLocals": true,
"noUnusedParameters": true
},
"exclude": ["node_modules"]
}
28 changes: 28 additions & 0 deletions packages/typescript/test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1181,6 +1181,34 @@ test.serial('picks up on newly included typescript files in watch mode', async (
t.true(usage, 'should contain usage');
});

// TODO: upgrade TypeScript when there is a release containing the fix for this issue
// https://github.com/microsoft/TypeScript/pull/41811. Then enable this test
// More details at https://github.com/rollup/plugins/issues/287. This fails with the message:
// Unexpected token (Note that you need plugins to import files that are not JavaScript)
test.serial.skip('works when code is in src directory', async (t) => {
const bundle = await rollup({
input: 'fixtures/src-dir/src/index.ts',
output: [
{
dir: 'fixtures/src-dir/dist',
format: 'esm'
}
],
plugins: [
typescript({
tsconfig: 'fixtures/src-dir/tsconfig.json'
})
],
onwarn
});
const output = await getCode(bundle, { format: 'esm', dir: 'fixtures/src-dir/dist' }, true);

t.deepEqual(
output.map((out) => out.fileName),
['index.js', 'types/index.d.ts', 'types/index.d.ts.map']
);
});

function waitForWatcherEvent(watcher, eventCode) {
return new Promise((resolve, reject) => {
watcher.on('event', function handleEvent(event) {
Expand Down

0 comments on commit 26e2a00

Please sign in to comment.